Comments in JSON
A common point of confusion, as the official JSON standard (RFC 8259) does not support comments.
Unlike JavaScript objects, standard JSON was designed purely as a data format and intentionally omits support for comments (e.g., // ...
or /* ... */
) to maintain its simplicity. Including comments in a JSON file will cause most standard parsers to fail with a syntax error.
Why No Comments?
The creator of JSON, Douglas Crockford, omitted comments to prevent people from using them to hold parsing directives, which would have complicated the format's purpose as a simple data carrier.
Workarounds
If you need comments, for example in configuration files, you can use:
- YAML: A human-readable format that is a superset of JSON and supports comments.
- JSONC (JSON with Comments): A non-standard variant used by tools like VS Code for configuration files. Files are parsed by stripping out comments before passing the text to a standard JSON parser.