DEV Community

Adam Siegel
Adam Siegel

Posted on • Originally published at jsonfyi.com

Every common JSON error, mapped to its fix (JS, Python, Postgres)

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()

Python · json.loads() / json.load()

Databases · PostgreSQL

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 }    // 
Enter fullscreen mode Exit fullscreen mode

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" }     // 
Enter fullscreen mode Exit fullscreen mode

Unquoted keys

{ name: "Ada" }       //  invalid (unquoted key)
{ "name": "Ada" }     // 
Enter fullscreen mode Exit fullscreen mode

JavaScript-style comments

{ "a": 1 /* note */ } //  invalid  JSON has no comments
{ "a": 1, "_note": "..." } //  use a sibling field
Enter fullscreen mode Exit fullscreen mode

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 } // 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)