Both methods res.send and res.json are identical when an array or object is passed. Res.json will convert non-objects such as null and undefined. You can format json with more options. This options can be set as:
spaces', 2);
app.set('jsonreplacer', replacer);
Then passed to JSON.stringify() like:
replacer, spacing);
// value: object toformat
// replacer: rulesfor transforming properties encountered during stringifying
// spacing: thenumber of spaces for indentation
The given below code in res.json() method is not in res.send method.
var replacer =app.get('json replacer');
var spaces =app.get('json spaces');
var body =JSON.stringify(obj, replacer, spaces);
It eventually calls res.send()
this.get('Content-Type')|| this.set('Content-Type', 'application/json');
return this.send(body);Read more