Possible Duplicate:
Can I comment a JSON file?
We are using a .json
file on a project. We want to know if we can add comments to the file and avoid crashing the JSON parser.
We've tried to do so with the following comment types, but they all crash the JSON file when it's parsed:
# I crash // I crash /* I crash */
Is there an acceptable form of commenting for JSON files?
Can I add a comment in JSON? No, JSON is a data-only format. Comments in the form //, #, or /* */, which are used in popular programming languages, are not allowed in JSON. You can add comments to JSON as custom JSON elements that will hold your comments, but these elements will still be data.
Adding Multiple-Line Comments in JSON Since JSON and strictly-linted JavaScript don't allow duplicate keys of values, you can add a unique letter or number to make it validate: { "//a": "This is the first comment.", "//b": "This is the second second." }
Reasons to use JSONC and not to allow comments in the regular JSON files are: It will separate your file from real JSON files. It is not going to bite you in the back when you add comment to a file where validation has to be applied, but you forget to remove comments because there is no error message.
We can have duplicate keys in a JSON object, and it would still be valid. The validity of duplicate keys in JSON is an exception and not a rule, so this becomes a problem when it comes to actual implementations.
JSON doesn't support comments – which is good when you think about it. However, someone has made JSON5 (https://github.com/aseemk/json5), which does, and may be of use to you.
It's worth pointing out that this is just someones JSON-like project, and is not an official spec, but then I guess JSON is just someones XML-like project that people liked :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With