2

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

1
  • Check the express settings its one of the settings (json spaces off the top of my head). It's automatically 0 on production mode. Commented Sep 30, 2012 at 7:15

2 Answers 2

4

a config setting was introduced in 3.0.0alpha1

try app.set('json spaces',0)

Sign up to request clarification or add additional context in comments.

2 Comments

Awesome! Looks like Express will actually automatically remove the white spaces in production env. More info here. So no changes needed.
Wow I added this to my app and it made js-yaml's output nice and spaceless!
1

you can also compress your output which will remove uncessary whitespaces by gzipping it.

  app.use(express.compress());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.