Re:Douglas Crockford: Why I removed comments from JSON
by polemic on Tuesday May 01, 2012 @05:02AM
(#3913530)
IMHO, the complexity that this would introduce just highlights why it's a good idea not to have them.
> "but I think it would be legal to reject JSON with duplicate keys."
No it would not. `SHOULD` has a very specific meaning:
SHOULD This word, or the adjective "RECOMMENDED", mean that there
may exist valid reasons in particular circumstances to ignore a
particular item, but the full implications must be understood and
carefully weighed before choosing a different course.
See http://www.ietf.org/rfc/rfc2119.txtAn object with duplicate keys must be parsed, but the exactly result will be implementation specific (undefined).
And what if you want multiple comments in the same scope (say, a comment before each attribute)? From the RFC: "The names within an object SHOULD be unique." In practice parsers will just override values, as JS does, but I think it would be legal to reject JSON with duplicate keys.