Almost every JSON.parse failure is one of these ten mistakes. Find yours in the table, then read on for the fix and how to decode the error message.
| Broken | Fixed | Problem |
|---|---|---|
{"a": 1,} | {"a": 1} | Trailing comma |
{'a': 1} | {"a": 1} | Single quotes |
{“a”: 1} | {"a": 1} | Smart quotes (Word, Docs) |
{a: 1} | {"a": 1} | Unquoted keys |
{"a": 1} // note | {"a": 1} | Comments |
{"a": 1} {"b": 2} | Two separate documents | Extra data after the JSON |
"line1↵line2" | "line1\nline2" | Raw line break in a string (↵) |
{"n": 0123} | {"n": 123} | Leading zeros |
{"x": NaN} | {"x": null} | NaN / Infinity |
{"a": 1 "b": 2} | {"a": 1, "b": 2} | Missing comma |
How to read a JSON.parse error message
Chrome, Edge and Node.js report failures like this: Expected double-quoted property name in JSON at position 7 (line 1 column 8). Three parts matter:
- The expectation — what the parser was looking for when it stopped; here a quoted key instead of
}. - position 7 — a zero-based character offset from the start of the input, counting spaces and line breaks.
- line 1 column 8 — the same spot in 1-based, human-friendly coordinates.
Firefox phrases the same idea as JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data. Two rules of thumb apply everywhere: the reported position is where the parser noticed the problem, so the real typo is often one token earlier; and only the first error is reported, so fix it, parse again, repeat.
Quoting and punctuation errors
1. Trailing commas
JavaScript tolerates a comma before a closing bracket; JSON does not. In [1, 2,] the comma promises another value that never arrives. Delete the last comma. Building JSON in a loop? Join the pieces with join(",") instead of appending a comma.
2. Single quotes
JSON strings and keys must use double quotes: {'name': 'Ann'} fails at the first quote. Retype with double quotes — but no blind find-and-replace: a value like "it's" holds a legitimate apostrophe a global swap would corrupt.
3. Smart quotes from Word or Google Docs
Autocorrect in Word, Docs and macOS turns straight quotes into typographic ones (“ ”) — different characters that the parser rejects on sight, even though they look identical in many fonts. Retype them in a plain-text editor or strip them before parsing.
4. Unquoted keys
Unlike a JavaScript object literal, JSON requires every property name in double quotes — even keys that would be legal bare identifiers. This bites when copying from a browser console, which prints objects with bare keys: quote {name: "Ann"} as {"name": "Ann"}.
5. Comments
JSON has no comment syntax: // and /* */ are both errors. They sneak in from JSONC files such as tsconfig.json, which VS Code tolerates but strict parsers reject. Strip every comment — if a note must survive, move it into a "_comment" property.
Structure and value errors
6. Extra data after the JSON
Unexpected non-whitespace character after JSON means the parser finished a complete value, then found more text — a second object pasted underneath, or an HTML error page glued to an API response. If the input is NDJSON (one object per line), parse each line separately; otherwise delete everything after the final bracket.
7. Literal line breaks inside strings
A JSON string may not contain raw control characters, and the newline is one. Multi-line text must use the two-character escape \n on a single line: "line1\nline2", never two visible lines. The same rule covers tabs (\t) and carriage returns (\r).
8. Numbers with leading zeros
The JSON number grammar forbids leading zeros: 0 and 0.5 are valid, 0123 and .5 are not. When the leading zero matters, as with IDs and ZIP codes, the value is really a string: quote it as "0123".
9. NaN and Infinity
NaN and Infinity are conveniences of JavaScript and Python, not JSON values. They appear when Python's json.dumps serializes an overflowed float, or when JSON is built with template strings instead of a serializer. Map them to null, or to "Infinity" if the distinction matters.
10. Missing comma between items
The mirror image of the trailing comma: {"a": 1 "b": 2} stops at "b" because the parser wanted a comma or a closing brace. Add the missing comma; when an error points at a healthy-looking token, look one token back.
Find the exact line in seconds
Decoding the message beats guessing, and a validator beats decoding. Try it: paste your broken JSON into the JSON Formatter & Validator and click Validate — the status line shows the parser's message and converts the reported position into an exact line and column. Once it parses, one click beautifies or minifies it, all locally in your browser.