Do JSON style object parameters always have to be in quotation marks?

Example:

myJSON = { param1:val1, param2:val2 } 

against.

 myJSON = { "param1":val1, "param2":val2 } 

Also, are there any browser compatibility issues or possible exceptions that may arise due to the use of one or the other?

+4
source share
1 answer

In JavaScript, names in object literals need not be surrounded by quotation marks, unless they are illegal JavaScript names (for example, they contain a special character, for example, a dash, they are a reserved word, etc.).

In the JSON data interchange format, all names must be surrounded by double quotation marks.

+5
source

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


All Articles