Every common JSON error mapped to its cause and fix — trailing commas, single quotes, 'Unexpected token', JSONDecodeError — each with a dedicated guide.
What causes most JSON errors?
Nearly every JSON parse failure comes from one of a few mistakes — a trailing comma, single quotes, an unquoted key, a comment, or a response that wasn't JSON at all (an HTML error page, an empty body). The parser reports the first character it can't accept, with a line and column. This guide maps every common error message to its cause and its fix, and links a focused walkthrough for each.
Match the error message to its fix
Parsers phrase the same underlying mistake differently across languages. Find the message you're seeing and jump to the guide that fixes it.
JavaScript · JSON.parse()
- Unexpected token … in JSON — a stray or missing character partway through. See Unexpected token in JSON.
- Unexpected token '<' — the server returned an HTML page, not JSON. See Unexpected token '<'.
- Unexpected end of JSON input — the document was truncated or empty. See Unexpected end of JSON input.
- Fails immediately at position 0 — empty string, BOM, or undefined. See JSON parse error at position 0.
- Converting circular structure to JSON — an object references itself. See circular structure to JSON.
- JSON.stringify returned undefined — the value can't be serialized. See JSON.stringify returns undefined.
Python · json.loads() / json.load()
- JSONDecodeError — the umbrella error, with a line, column, and char offset. See Python JSONDecodeError.
- Expecting property name enclosed in double quotes — single-quoted keys or a Python dict. See Expecting property name enclosed in double quotes.
- No JSON object could be decoded — the older Python 2 / requests phrasing for a non-JSON body. See No JSON object could be decoded.
Databases · PostgreSQL
- invalid input syntax for type json — single quotes, an empty string, or double-encoded JSON in an INSERT. See Postgres: invalid input syntax for type json.
The mistakes behind most syntax errors
Whatever the message, the underlying cause is usually one of these. Each is invalid JSON even though it looks fine at a glance.
Trailing commas
{ "a": 1, "b": 2, } // ✗ invalid
{ "a": 1, "b": 2 } // ✓
The single most common JSON error. See trailing commas in JSON for why every strict parser rejects them and how JSON5/JSONC differ.
Single-quoted strings
{ 'name': 'Ada' } // ✗ invalid (single quotes)
{ "name": "Ada" } // ✓
Unquoted keys
{ name: "Ada" } // ✗ invalid (unquoted key)
{ "name": "Ada" } // ✓
JavaScript-style comments
{ "a": 1 /* note */ } // ✗ invalid — JSON has no comments
{ "a": 1, "_note": "..." } // ✓ use a sibling field
JSON has no comment syntax at all. See JSON comments for five practical workarounds.
Wrong literals
{ "ok": True, "x": None } // ✗ Python literals
{ "ok": true, "x": null } // ✓
Unescaped control characters
Real newlines and tabs inside strings are illegal — escape them: \n, \t. See how to escape characters in JSON for the complete table.
Duplicate keys
{ "id": 1, "id": 2 } // ⚠ legal but unpredictable
RFC 8259 says names should be unique, so duplicates parse but most parsers silently keep the last value. See are duplicate keys valid in JSON? for what each parser does.
Numeric oddities
- No leading zeros: 007 is invalid. Use 7.
- No NaN, Infinity, or undefined — use null when you mean "no value".
- No hexadecimal: 0xFF is invalid.
Find the exact character
The fastest way to locate any of these is to paste the document into a validator that reports the precise line and column. If you'd rather see structural problems — trailing commas, duplicate keys, comments — flagged as warnings, use the JSON linter. To confirm the shape of your data against required fields and types, use the JSON Schema validator.
New to the format? Start with what is JSON and the data types reference.
Top comments (0)