Express: JSON payloads no longer "pretty"

Created on 12 Apr 2014  路  2Comments  路  Source: expressjs/express

hi,

in express 3.x I did

res.contentType('application/json');
res.send(200, {
    foo : 'bar'
});

return "pretty" JSON, in the browser and also in tools like Postman.

in express 4.x I do

res.set('Content-Type', 'application/json');
res.send(200, {
    foo : 'bar'
});

and JSON is not formatted anymore.

Checked headers, content type header is set correctly.

Is there any way to return to the old formatted way?

thx

Most helpful comment

For anyone else looking at this, app.set('json spaces', 2); is the configuration required to send pretty json.

All 2 comments

We turned it off by default. Just us a browser extension.

For anyone else looking at this, app.set('json spaces', 2); is the configuration required to send pretty json.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prashantLio picture prashantLio  路  3Comments

dmaks9 picture dmaks9  路  3Comments

cuni0716 picture cuni0716  路  3Comments

AndrewEQ picture AndrewEQ  路  4Comments

ER-GAIBI picture ER-GAIBI  路  3Comments