Is it possible to comment on a JSON file?

Asked

Viewed 19,183 times

20

Can I comment on a JSON file? If so, how?

  • It is famous. http://stackoverflow.com/questions/244777/can-i-comment-a-json-file

4 answers

29


No. Unable to comment on JSON.

  • I had given +1, despite the prolixity (a simple "no" would suffice :P), but I’m almost withdrawing... XML also stores data, but it supports comments. In time: I think it’s very good JSON does not allow comments, makes it yours Parsing simple and fast, but the fact of being a data format does not exclude the possibility of supporting comments.

  • @mgibsonbr is that I felt a little strange when answering only with the first sentence, so I decided to add an explanation of why it doesn’t make sense. But you’re right, although it makes no sense you can comment on XML, which would make my second sentence incorrect :/

  • 1

    I know, I commented in jest even, beyond what the system would not leave an answer (or even a comment) only with 3 letters... :) As for XML, one can say that the comments are meta-data, as well as the DTD and possibly other things I don’t even know. A "semantic" JSON could have comments, only these comments would have the same syntax as the other data (but hopefully this doesn’t happen, JSON is so good simple as it is!).

  • Anyway, I hope I haven’t caused you any discomfort, I’d better remove my comments?

  • 1

    No need to remove it, your comments are more informative than my answer, rsrs.. but I tell you I was more confused than I was before. I think I’ll leave it the way it is, because it’s as simple as JSON :)

  • I preferred the long. Why is it? : P

Show 1 more comment

18

10

No. It was made to contain no comments, it is only a data structure formatted as object.

NOTE if even some kind of comment is needed, you can insert one more field within your object called commentor something like...

4

The specification does not allow, but if you have already sold your soul to the devil and someone is pointing a gun at your head, you can apply a gambiarra.

To a parser that does not obtain JSON through streaming, If the same key is declared more than once, the value that will be worth in the end is what appears last. Then, to comment on a key, create another key of the same name above it. So:

{
    "pessoa": "A pessoa a quem este arquivo se refere",
    "pessoa": {
        "nome": "O nome da pessoa",
        "nome": "John Doe"
    }
}

Just emphasizing what I’ve said before, but in other words: if you do this above you solve a problem now, but you will go straight to hell soon after.

I got this idea from Soen’s most controversial post to date:

Can comments be used in JSON?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.