Express: Option to append trailing newline to json responses

Created on 14 Mar 2019  路  7Comments  路  Source: expressjs/express

Appending a trailing newline would make it easier to look at json-returning endpoints with curl.
I don't see any major issues with making a trailing newline the default; however if that is not possible, then I'd love a new app setting e.g. "json append" that allows a developer to append a newline.

All 7 comments

Do you also set the indent setting? My thought for asking is that since indent adds newlines already, maybe we could add a trailing newline just based on that being set. Just a thought I had that perhaps when you want a trailing newline it's when the response has the indentation turned on too?

Do you also set the indent setting?

It would be orthogonal to the indent setting.

If I did: res.json({foo:1, bar: 42}) I'd want a body of: {"foo":1, "bar": 42}\n
If I turned on indentation of 2, I'd expect: {\n "foo":1,\n "bar": 42\n}\n

Gotcha. So it sounds like this would need to be an entirely new setting then, as we do need a newline-less json response method. That would be vs just unconditionally adding a trailing newline to all responses.

馃憥

Gotcha. So it sounds like this would need to be an entirely new setting then, as we do need a newline-less json response method. That would be vs just unconditionally adding a trailing newline to all responses.

Would you like me to write a pull request? Or is it easier for you to complete it yourself?

Express should limit to conforming with HTTP and JSON specs in this case, which it does. All other modifications for personal requirements should be handled by users themselves.

The OP could use the -w option in curl itself. curl --write-out "\n" ... (-w "\n" for short) will add a newline after the response. For more -w prowess, the man pages for curl should have you covered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wxs77577 picture wxs77577  路  3Comments

dmaks9 picture dmaks9  路  3Comments

AndrewEQ picture AndrewEQ  路  4Comments

Domiii picture Domiii  路  3Comments

extensionsapp picture extensionsapp  路  3Comments