0
0
Expressframework~5 mins

res.json for JSON responses in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does res.json() do in Express?

res.json() sends a JSON response to the client. It converts a JavaScript object or array into JSON format and sets the correct headers automatically.

Click to reveal answer
beginner
How do you send a JSON object { message: 'Hello' } using res.json()?

Use res.json({ message: 'Hello' }). This sends the JSON { "message": "Hello" } to the client.

Click to reveal answer
beginner
What HTTP header does res.json() set automatically?

It sets Content-Type: application/json so the client knows the response is JSON.

Click to reveal answer
beginner
Can res.json() send arrays as well as objects?

Yes! You can send arrays like res.json([1, 2, 3]) and Express will convert it to JSON format.

Click to reveal answer
intermediate
What happens if you pass a non-serializable value to res.json()?

Express will throw an error because it cannot convert functions or undefined values to JSON.

Click to reveal answer
What does res.json() do in Express?
AReads JSON from the client
BRedirects to another URL
CSends a JSON response to the client
DSends plain text response
Which header does res.json() set automatically?
AContent-Type: text/html
BContent-Type: text/plain
CContent-Type: multipart/form-data
DContent-Type: application/json
How would you send the JSON object { success: true } in Express?
Ares.json({ success: true })
Bres.send({ success: true })
Cres.redirect({ success: true })
Dres.render({ success: true })
Can res.json() send an array as a response?
ANo, only objects
BYes, arrays and objects
COnly strings
DOnly numbers
What happens if you pass a function to res.json()?
AIt throws an error
BIt converts the function to JSON
CIt ignores the function
DIt sends the function as text
Explain how res.json() works in Express and why it is useful.
Think about how servers send data to browsers in a format they understand.
You got /4 concepts.
    Describe a situation where you would use res.json() in a web app.
    Imagine building a simple app that shows user info fetched from the server.
    You got /4 concepts.