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.

  • SyntaxError: Unexpected token '/', ..."1 // count"... is not valid JSON
  • SyntaxError: JSON.parse: unexpected character at line 2 column 12 of the JSON data

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.

Fails to parse
{
  // how many items
  "count": 1
}
Parses
{
  "_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.

No cookies, no accounts, no tracking. Your JSON and text are processed entirely in your browser and never sent anywhere. We count anonymous page views (the page address only, nothing about you or your device), and use localStorage to remember your theme.