JSON does not support comments
JSON has no comment syntax. // and /* */ both cause a parse error. Here is why, what to do instead, and which JSON-like formats do allow them.
Open the JSON formatterWhat the error looks like
Different engines word this differently. You may see any of these:
Why it happens
- JSON was designed as a data interchange format, and comments were left out on purpose so that parsers could stay simple and no one would be tempted to put parsing directives in them.
- Configuration files are where this bites, because configuration is exactly where an explanation is most useful.
Example
{
// the display name
"name": "My Mosaic",
/* version */
"version": 2
}
{
"_comment": "name is the display name",
"name": "My Mosaic",
"version": 2
}
How this tool reports it
The formatter reports each comment and offers to strip them, leaving the rest of the document exactly as it was.
Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.
Worth knowing
- A conventional workaround is a property whose name marks it as a note, such as _comment. It is ugly, but it is valid and it survives a round trip.
- JSONC, used by tsconfig.json and VS Code settings, does allow comments. JSON5 allows them too. Neither is JSON, and neither will parse with JSON.parse.