Response JSON object or JSON.stringify?

express, json, node.js

Solution

If you send the response with express's `res.json` you can send the Object directly as `application/json` encoded response.

app.get('/route/to/ressource', function(req, res){
  var oMyOBject = {any:'data'};

   res.json(oMyOBject);
});

Problem

Suppose I want to return JSON content ``` var content = { a: 'foo', b: 'bar' }; ``` What is the best practice to return my JSON data? A) Return object as is; i.e `res.end(content)`? B) `JSON.stringify(content)` and then call `JSON.parse(content)` on the client?

Original source