View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

res.json()

Sends a JSON response composed of a stringified version of the specified data.

Usage

return res.json([statusCode, ] data);

Details

This method is identical to res.send() when an object or array is passed, however it may be used for explicit JSON conversion of non-objects (null, undefined, etc), though these are technically not valid JSON.

Example

res.json(null)
res.json({ user: 'tobi' })
res.json(500, { error: 'message' })

Notes

  • Don't forget this method's name is all lowercase.
  • This method is terminal, meaning it is generally the last line of code your app should run for a given request (hence the advisory usage of return throughout these docs).

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book