Comments are not allowed in JSON
SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)
Where it stops
{
// how many items
"count": 1What it means
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.
Last verified on Chromium 145, Firefox 146, WebKit 26 and Node 20.
It opens with the error marked. Nothing is uploaded. Find where the error is.
- Usually
- Copying from a JSONC config fileDocumenting a payload before sending itCommenting out a block during debugging
- Fix
- Remove the comment.
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
}Line 2 changes.
{
"_comment": "how many items",
"count": 1
}How the message appears
Chrome and Node first, then Firefox, then Safari. Older versions of Chrome and Node word it differently. Those lines are marked.
- SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)Chrome and Node
- SyntaxError: JSON.parse: expected property name or '}' at line 2 column 3 of the JSON dataFirefox
- SyntaxError: JSON Parse error: Unrecognized token '/'Safari
- SyntaxError: Expected ',' or '}' after property value in JSON at position 15 (line 2 column 14)
- SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 2 column 14 of the JSON data
- SyntaxError: Expected property name or '}' in JSON at position 4Older V8 wording
What causes it
Copying from a JSONC config file
tsconfig.json,.eslintrc.jsonand VS Code’ssettings.jsonare 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.
Worth knowing
NoteJSON5 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.
NoteYAML supports # comments and is a superset of JSON, which is why config formats that need comments so often end up as YAML.