REST / JSON: Should I include a new line after a JSON line?

If I return ["foo"] from a RESTful web request, which ones are more correct? Will pedantic REST analysis die on a new line?

["foo"]\n     (with newline, Content-Length=8)
["foo"]       (no newline, Content-Length=7)

For easy regression testing, I like the form with a new line, but I want to make sure that I will not break any application platforms that may have a more strict form in the REST format.

+3
source share
2 answers

Quote from RFC 4627 , a bold corresponding section for emphasis.

JSON - .    , , .

JSON .

 JSON-text = object / array

:

 begin-array     = ws %x5B ws  ; [ left square bracket

 begin-object    = ws %x7B ws  ; { left curly bracket

 end-array       = ws %x5D ws  ; ] right square bracket

 end-object      = ws %x7D ws  ; } right curly bracket

 name-separator  = ws %x3A ws  ; : colon

 value-separator = ws %x2C ws  ; , comma

    .

+4

, JSON . , JSON.org : " ", , .

+1

Source: https://habr.com/ru/post/1741864/


All Articles