Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are whitespace characters insignificant in JSON?

Tags:

json

Are blank characters like spaces, tabs and carriage returns ignored in json strings?

For example, is {"a":"b"} equal to {"a" : "b"}?

like image 973
user496949 Avatar asked Nov 11 '10 01:11

user496949


People also ask

Does white space matter in JSON?

Whitespace (Space, Horizontal tab, Line feed or New line or Carriage return) does not matter in JSON.

Are spaces allowed in JSON?

Format JSON files to be human readable. Use four spaces for indentation (matching OpenStack conventions used in Python and shell scripts). Do not use tab characters in the code, always use spaces. Use one space after the name-separator (colon).

How does JSON handle space in value?

If you want to use " in your String use escape character which is most often \ . Examples: "Deutchland" , "Costa Rica" , "He said \"whatever\" " . Integer value can be without quotes, but it's a good practice to quote them and later cast those Strings to proper numeric types.


1 Answers

Yes, blanks outside a double-quoted string literal are ignored in the syntax. Specifically, the ws production in the JSON grammar in RFC 4627 shows:

Insignificant whitespace is allowed before or after any of the six structural characters.     ws = *(              %x20 /              ; Space              %x09 /              ; Horizontal tab              %x0A /              ; Line feed or New line              %x0D                ; Carriage return          ) 
like image 171
Greg Hewgill Avatar answered Sep 27 '22 18:09

Greg Hewgill