Skip to content
jsonblocks

How to fix invalid JSON: 7 common errors

Nearly every JSON syntax error is one of seven mistakes: trailing commas, single quotes, unquoted keys, comments, truncation, wrong literals, or bad escapes. Find yours below and apply the before-and-after fix.

Start by pasting the document into the validator to get the exact line and column. Then match the failure against these seven patterns - they cover the overwhelming majority of real-world breakage.

1. Trailing comma

json
// Broken: comma after the last item
{ "a": 1, "b": 2, }

// Fixed
{ "a": 1, "b": 2 }

JavaScript allows trailing commas; JSON never does. If the error points at a closing brace or bracket, look immediately before it.

2. Single quotes

json
// Broken
{ 'name': 'Ada' }

// Fixed
{ "name": "Ada" }

JSON strings and keys demand double quotes. Python repr output and hand-typed snippets are the usual sources of single quotes.

3. Unquoted keys

json
// Broken: JavaScript object literal
{ name: "Ada" }

// Fixed
{ "name": "Ada" }

Bare words are legal in JavaScript and YAML but not in JSON. Quote every key.

4. Comments

json
// Broken
{
  // user record
  "name": "Ada"
}

// Fixed: delete the comment, or keep it as data
{
  "_comment": "user record",
  "name": "Ada"
}

5. Truncated paste

json
// Broken: ends mid-document
{ "users": [{ "name": "Ada" }

// Fixed: close every opened bracket
{ "users": [{ "name": "Ada" }] }

"Unexpected end of JSON input" always means truncation: a clipped copy, a capped log line, or a download that stopped early. Count opening versus closing brackets.

6. Non-JSON literals

json
// Broken: JavaScript values
{ "a": undefined, "b": NaN }

// Fixed
{ "a": null, "b": null }

undefined, NaN, and Infinity exist in JavaScript but not in JSON. The equivalent is almost always null.

7. Bad escapes and smart quotes

json
// Broken: raw newline and curly quotes
{ "text": "line one
line two", “key”: 1 }

// Fixed
{ "text": "line one\nline two", "key": 1 }

Control characters must be escaped (\n, \t, \"), and word processors love replacing straight quotes with curly ones. Paste through a plain-text editor when in doubt.

Frequently asked questions

What is the fastest way to find a JSON error?

Paste the document into the JSON validator. It reports the exact line and column, shows the offending line, and suggests the likely fix.

Why does JSON forbid trailing commas and comments?

Strictness is the point: a tiny grammar means parsers in every language agree exactly. For human-friendly configs with comments, use JSONC, YAML, or TOML instead.

My JSON looks fine but still fails. What now?

Suspect invisible characters: smart quotes from rich text, a byte-order mark at the file start, or mixed line endings. Re-paste through a plain-text editor and re-validate.