is there a way to prettyfy JSON response in Express 4?

2,942 views
Skip to first unread message

Bojan Djurkovic

unread,
Apr 30, 2014, 3:24:25 PM4/30/14
to expre...@googlegroups.com
In Express 3 we had app.locals.pretty but that doesn't take effect in Express 4. Also 'json spaces' setting was removed. It would be nice to be able to set pretty JSON responses for when working in dev/local environments for example.

Thanks,

Bojan

Павел Климашкин

unread,
May 1, 2014, 1:37:17 PM5/1/14
to expre...@googlegroups.com
Not necessarily call res.json();
You can response json with this command:
res.set({'Content-Type': 'application/json; charset=utf-8'}).send(200, JSON.stringify({prop: 'hello', prop2: 'Hello2'}, undefined, ' '));
This will insert '\n' to prettify output

среда, 30 апреля 2014 г., 23:24:25 UTC+4 пользователь Bojan Djurkovic написал:

Jishnu Viswanath

unread,
Apr 30, 2014, 4:51:01 PM4/30/14
to expre...@googlegroups.com

Chrome has plugin for that.

--
You received this message because you are subscribed to the Google Groups "Express" group.
To unsubscribe from this group and stop receiving emails from it, send an email to express-js+...@googlegroups.com.
To post to this group, send email to expre...@googlegroups.com.
Visit this group at http://groups.google.com/group/express-js.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages