Let's assume JSON supports comments, and `foo` is a JSON document with comments, what should happen here?
JSON.stringify(JSON.parse(foo))
Presumably you'd say that it should return a plain JSON object without comments, right? However, with the current implementation this will return a JSON document that is identical to the input, modulo whitespace. This makes it easy to write tools that can, for example, increment the version number in a nodejs package.json file programatically. Doing this in a world where comments exist becomes extremely awkward or at the very least annoying, because either you have to write your own JSON parser that preserves comments, or you have to simply discard the comments when you're writing the file.
If you go with the first option, you'll inevitably run into a scenario where you have a document like this contrived example:
{
// this is the first ever version!
"version": "1.0.0"
}
And your tool goes off and increments the version number, so you end up with:
{
// this is the first ever version!
"version": "2.0.0"
}
and now your comment is a lie.
If you go with the second option, you destroy all comments whenever you write data back to the file, so they can be deemed temporary at best.
What benefit do you actually get from having comments in either scenario?
Comments are appropriate in JSON which is written by humans. If it's written by a machine, of course comments are irrelevant. Situations where you need to automatically make changes to JSON which is primarily maintained by humans are a bit of a special case that I don't think is worth optimizing for; if you feel putting comments in object fields is a better choice in this situation, you can still do that even if comments are supported.
Supporting comments makes JSON more convenient to use in more situations, and it doesn't prevent you from doing anything you can do now.
If you go with the first option, you'll inevitably run into a scenario where you have a document like this contrived example:
And your tool goes off and increments the version number, so you end up with: and now your comment is a lie.If you go with the second option, you destroy all comments whenever you write data back to the file, so they can be deemed temporary at best.
What benefit do you actually get from having comments in either scenario?