4 ms·
From json.org: "JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to
by gnuvince 15y ago
From json.org:
"JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate."
Humans are mentioned before machines. Comments improve human readability. Furthermore, comments are very simple to implement, and don't lower the ease of parsing.
- philjohn 15y agoAnd as Crockford said, if you want comments in your JSON, knock yourself out - just strip them out before handing it over to your parser.
- TazeTSchnitzel 15y agoYeah, but JSON is a data interchange format. It's like adding the ability to add comments to arbitrary binary data, it's rather pointless. It's supposed to be human readable, but ultimately it's for machines. It's just easier to debug.
- cube13 15y agoThere are 3 mutually conflicting goals of JSON: 1. Machine parsing/generation 2. Human parsing/generation 3. Ability to transmit it in a parsable format through HTTP #1 conflicts with both #2 and #3. It conflicts with #1 because binary data formats are much easier to parse, and are generally smaller on the wire than plain text formats. Also, it conflicts with #3 for the same reason, since HTTP is a plain text format, and JavaScript generally deals with plain text better than binary data. #2 conflicts with #3, because comments are nice for human readability, but should never be sent on the wire, because they are not necessary to parse the sent data. If your comment is important, it should be a data element that's sent on the wire. The end result is a compromise. Since two of the concerns effectively make comments useless, the compromise should be towards those two. In addition, the reason given by Crockford makes quite a bit of sense. JSON, much like XML, is a format for the transmission of data. Everything in a given JSON object should be important. It's not a programming language, which means that control directives are unnecessary.