Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  71] [ 6]  / answers: 1 / hits: 26160  / 15 Years ago, thu, january 14, 2010, 12:00:00

The JSON spec says that JSON is an object or an array. In the case of an object,



An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members). A name is a
string.
...



And later, the spec says that a string is surrounded in quotes.


Why?


Thus,


{"Property1":"Value1","Property2":18}

and not


{Property1:"Value1",Property2:18}

Question 1: why not allow the name in the name/value pairs to be unquoted identifiers?




Question 2: Is there a semantic difference between the two representations above, when evaluated in Javascript?


More From » json

 Answers
4

Question 1: why not allow the name in the name/value pairs to be unquoted identifiers?




The design philosophy of JSON is Keep it simple



Quote names with is a lot simpler than You may quote names with or ' but you don't have to, unless they contain certain characters (or combinations of characters that would make it a keyword) and ' or may need to be quoted depending on what delimiter you selected.




Question 2: Is there a semantic difference between the two representations above, when evaluated in Javascript?




No. In JavaScript they are identical.


[#97827] Tuesday, January 12, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marquezb

Total Points: 237
Total Questions: 97
Total Answers: 89

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
;