Can we use comments in a JSON file?
Well the short answer is: No!
Can we use comments in a JSON file?
Image from https://www.nylas.com/blog/the-complete-guide-to-working-with-json/
Well the short answer is: No!
Comments of the form //… or /*…*/ are not allowed in JSON. This answer is based on the official JSON documentation below:
- https://www.json.org
- RFC 4627: The
application/jsonMedia Type for JavaScript Object Notation (JSON) - RFC 8259 The JavaScript Object Notation (JSON) Data Interchange Format (supercedes RFCs 4627, 7158, 7159)
However if you really need to nothing stops you from putting the comment in the JSON like "_comment" and have your application to ignore it when parsing the JSON data.
Here is an example:
{ "_comment": "this is a very useful comment ...", "glossary": { "title": "example glossary", "GlossDiv": { "title": "S" } }}
Cheers!