3 ms·
Comments were intentionally excluded from JSON, lest they be used to instruct the parser and cause fragmentation of the ecosystem.
by sneak 6y ago
Comments were intentionally excluded from JSON, lest they be used to instruct the parser and cause fragmentation of the ecosystem.
- arcatek 6y agoI know it's the official reason, but it's also a really bad one - nothing prevents current JSON parsers to add some weird syntactic rules inside plain strings (similar to "use strict" in JS), but you don't see that happen. It's always been a completely hypothetical issue. The only real reason why comments would be problematic is that they are a pain to preserve in a consistent way when editing a file, and thus would require extra work in parsers / serializers. Still, it would be worth the cost imo.
- HelloNurse 6y agoIn most applications reading and writing JSON are completely separate operations and roundtripping comments makes no sense. Actual JSON-reading applications must ignore comments because they aren't allowed to care about them. On the other hand anything useful can be placed in a proper field, a comment would be a hack to pass information to human readers but not to JSON consumers (saving some time and memory). Such a technique could only be considered if people are supposed to read the JSON files and some information is useful for them but not for the reading application: a niche within a niche. Preserving comments would actually be a complicated special purpose feature, reserved for something like structured text editors that can perform nonstandard parsing with comments included in their special object model (of the large Javascript subset/superset/variant they choose to support and roundtrip, not of JSON).
- sneak 6y agoI agree that it was stupid. I am 100% pro-comment.