How browsers word it
| Chrome and Node (V8), objects | Expected double-quoted property name in JSON at position 7 (line 1 column 8) |
|---|---|
| Chrome and Node (V8), arrays | Unexpected token ']', "[1,2,]" is not valid JSON |
| Chrome and Node, older | Unexpected token } in JSON at position 7 |
| Firefox | JSON.parse: expected double-quoted property name at line 1 column 8 of the JSON data |
Common causes
A comma after the last property
Editing by hand or generating JSON with a loop that writes a comma after every item leaves one before the closing brace.
Input
{"a":1,}JSON Formatter says
Trailing comma before "}" is not allowed in JSON
A comma after the last array element
The same mistake in an array. JavaScript and many config formats allow it, JSON does not.
Input
[1,2,]
JSON Formatter says
Trailing comma before "]" is not allowed in JSON
Comments in the file
Files such as tsconfig.json and editor settings allow comments and trailing commas (JSONC), but a strict JSON parser rejects them.
Input
{"a":1, // note "b":2}JSON Formatter says
Expected a key in double quotes but found "/"
How to fix it
- Remove the comma before the closing } or ].
- Generate JSON with a serializer such as JSON.stringify instead of joining strings.
- If the file is JSONC, strip the comments and commas before parsing, or use a parser that supports them.
- Paste the text into the JSON formatter: it names the line and column of the first problem.