Do the JSON keys have to be surrounded by quotes?

后端 未结 6 943
生来不讨喜
生来不讨喜 2020-11-22 11:23

Example: Is the following code valid against the JSON Spec?

{
    precision: \"zip\"
}

Or should I always use the following syntax? (And if

6条回答
  •  -上瘾入骨i
    2020-11-22 12:13

    Yes they do. But if you need otherwise, checkout JSON5.

    JSON5 is a superset of JSON that allows ES5 syntax, including:

    • unquoted property keys
    • single-quoted, escaped and multi-line strings
    • alternate number formats
    • comments
    • extra whitespace

    The JSON5 reference implementation (json5 npm package) provides a JSON5 object that has parse and stringify methods with the same args and semantics as the built-in JSON object.

提交回复
热议问题