On Node.js using Express, I am outputting JSON with a simple response.send(myObject) It's working fine, but the response has a lot of white spaces indentations. Removing them reduces the size by half. Is there a quick/proper way to do this? I tried using JSON.stringify and it works great, but that turns the response type to text/html
-
Check the express settings its one of the settings (json spaces off the top of my head). It's automatically 0 on production mode.Jonathan Ong– Jonathan Ong2012-09-30 07:15:59 +00:00Commented Sep 30, 2012 at 7:15
Add a comment
|
2 Answers
a config setting was introduced in 3.0.0alpha1
try app.set('json spaces',0)
2 Comments
pixelfreak
Awesome! Looks like Express will actually automatically remove the white spaces in production env. More info here. So no changes needed.
CommaToast
Wow I added this to my app and it made js-yaml's output nice and spaceless!