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

cuni0716 picture cuni0716  路  3Comments

nove1398 picture nove1398  路  3Comments

prashantLio picture prashantLio  路  3Comments

wxs77577 picture wxs77577  路  3Comments

gaurav5430 picture gaurav5430  路  3Comments