4 ms·
It has always bothered me that the JSON standard does not allow for comments. Especially when you want to annotate some sample response/request.
by kennell 11y ago
It has always bothered me that the JSON standard does not allow for comments. Especially when you want to annotate some sample response/request.
- creshal 11y agoIt's an oversight, but does it really matter anywhere? YAML can be used for a JSON-y syntax that allows comments, which is good enough for most use cases.
- wnevets 11y agoIIRC douglas crockford purposely didn't include comments
- daxelrod 11y agoThey were explicitly removed: https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaGSr https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaG... HN discussion: https://news.ycombinator.com/item?id=3912149 https://news.ycombinator.com/item?id=3912149
- wnevets 11y agoSo definitely a thought out and purposeful decision, thanks for the links.
- deleted 11y ago[deleted]
- rrauenza 11y ago...and the lack of trailing commas.
- andreynering 11y agoIt's just a hack, but you can write a comment in a key that is supposed to be ignored: { "__comment": "The following config does...", "key": "value" } But I agree that it is not much intuitive.
- spriggan3 11y agoJSON isn't semantic so there is no need to put __ before comment, it's not like it's meta or something. It will still be parsed and processed by the JSON parser, which is a waste of computer cycle.
- oconnor663 11y agoIt's kind of a future-proofing thing. If you put a field called "comment" in a JSON blob, especially one in a format you don't control, you run the risk that future versions of the format will define the "comment" field and give it actual meaning. A crazy prefix makes this at least slightly less likely.
- nucleardog 11y agoThey were removed because people started trying to use them to hold additional parsing directives and other meta-information which would have destroyed interoperability and defeated the entire purpose of a simple interchange format. See: https://groups.yahoo.com/neo/groups/json/conversations/topics/156 https://groups.yahoo.com/neo/groups/json/conversations/topic... If you want to annotate JSON in documentation, I say "go ahead and just use //". Any programmer reading it will understand that those lines are taken to be comments and they shouldn't type them in their final request.