Comments are not allowed in JSON
JSON deliberately has no comments. They were removed from the format early on, on the grounds that people would use them to carry parsing directives — so // and /* */ are both syntax errors.
How the message appears
The same fault, worded by different engines. V8 (Chrome, Node, Edge) changed its format around Chrome 109, so older and newer runtimes disagree about the same document.
What causes it
Copying from a JSONC config file
tsconfig.json, .eslintrc.json and VS Code’s settings.json are JSONC, not JSON. VS Code parses them with a comment-tolerant reader, which is why comments work there and nowhere else.
Documenting a payload before sending it
Annotating an API request body while testing. The comment has to come out before the request goes out.
Commenting out a block during debugging
There is no way to do this in JSON. Delete the block, or move the value under an unused key.
The fix
Remove the comment. If the note has to travel with the data, put it in a real key — _comment is the usual convention — and have consumers ignore keys beginning with an underscore.
{
// how many items
"count": 1
}{
"_comment": "how many items",
"count": 1
}The example travels in the URL fragment, which browsers never send to a server.
Worth knowing
- JSON5 and JSONC both support comments. If you control every reader, either is a reasonable choice; if the file crosses a boundary you do not control, it is not.
- YAML supports
#comments and is a superset of JSON, which is why config formats that need comments so often end up as YAML.