On Jul 11, 2017, at 06:14, J Decker <[email protected]> wrote:
> 
> Why does JSON have quoted field names anyway (which I could understand if 
> they included spaced).

Douglas Crockford has explained this bit of history in talks about JSON:

Originally, they weren’t quoting map keys (names of object members) if they 
looked like identifiers in JavaScript.  (In early JavaScript-based 
implementations, JSON data was directly fed as code into the JavaScript 
interpreter so there was no need to write a decoder.)

But then some application was using “do” as a map key.  “do” happens to be a 
reserved word in JavaScript, breaking the decoding process.  So they had to 
check if the map keys were reserved words and quote them in that case.  That 
set then would have to become part of the JSON specification.  Worse, the set 
of reserved word in JavaScript could (theoretically) change, so either the JSON 
specification would need to change, too, or the next version of JavaScript 
would no longer support direct use of JSON as JavaScript code.

So they decided to simply always quote, and that was that.

The approach to execute JSON as JavaScript code of course is history now, but 
JSON hasn’t changed back.

Actually, with RFC 7159 and ECMA 404 out and JSON very widely implemented, any 
proposal to change the JSON syntax is a complete non-starter.

(Most of these proposals come from people who notice that JSON is bad for 
conversing about data or for human input.  Well, that is not what JSON is meant 
for.  DO NOT USE JSON FOR CONVERSING ABOUT DATA OR FOR HUMAN INPUT.  JSON is an 
interchange format.  There are much better formats for humans inputting and 
conversing about JSON-modeled data, such as YAML, which is even a superset of 
JSON.  No point in messing around with JSON if the problem has already been 
solved.)

Of course, if saving bytes is your objective, you might want to look at CBOR.  
I wonder when that is picked up by the JavaScript spec (there are libraries, of 
course).

Grüße, Carsten

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to