简体   繁体   中英

In What Standard is it Made Official That JSON Object Property Names Must Be Double-Quoted?

Checked here:

http://www.json.org/

and here:

http://www.ietf.org/rfc/rfc4627.txt?number=4627

All I'm seeing is that names must be strings, not that they can't use single-quotes. Don't get me wrong, I'm on board with quoted names for JSON. It protects devs from using property names that aren't legit JS variable names and also powerful use of JSON frequently puts traditional values in property-names for things like map-reduction of 2D arrays modeling tables.

I also think it would make sense for all names to consistently use one or the other quote-type in order to avoid assumptions one might make while trying to parse JSON in some language that doesn't have convenient JSON parsing libraries/native-methods coming out of its pores, but I don't see anything in these specs that insists it must be double or single.

All I see in the second link is that they must be strings. Where is it established that they must be double-quoted as a lot of the JSON validators seem to think? Is there another source? If so who own JSON town? I'm feeling like a raggedy-man who lost his way.

From page 4 of the RFC that you link to:

string = quotation-mark *char quotation-mark
...
quotation-mark = %x22      ; "

Property names must be strings, but strings must be delimited with quotation marks (not apostrophes).

See also the diagram of a string on json.org. Note that it starts and ends with " and not branches that would allow ' as an alternative.

Taken from the http://www.json.org site:

Strings are defined as a character sequence enclosed in double quotes.

In the RFC:

string = quotation-mark *char quotation-mark

where

quotation-mark = %x22      ; "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM