Do the JSON keys have to be surrounded by quotes?

后端 未结 6 960
生来不讨喜
生来不讨喜 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条回答
  •  暖寄归人
    2020-11-22 12:16

    From 2.2. Objects

    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 from 2.5. Strings

    A string begins and ends with quotation marks.

    So I would say that according to the standard: yes, you should always quote the key (although some parsers may be more forgiving)

提交回复
热议问题