Sending JSON Responses
A growing trend has been to use JSON data to transfer information from a server to a client and then have the client dynamically populate the HTML elements on the page rather than have the server build HTML documents or parts of HTML documents and send the HTML to the client. Express facilitates sending JSON very nicely by providing the json() and jsonp() methods on the Response object. These methods use a syntax similar to that of send(), except that the body is a JSON stringify JavaScript object:
res.json(status, [object])res.json([body])res.jsonp(status, [object])res.jsonp([object])
The JavaScript object is converted to a JSON string and sent back to the client. In the case of jsonp(), the URL of the request object includes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access