JSON Parse Errors: 10 Common Failures and How to Fix Them

2024-09-12

API responses and config files often fail with a single-line parse error. This guide covers ten common mistakes—each with a broken example, the cause, and the corrected JSON—plus how to locate the line in our online formatter.

1. Single quotes for keys or strings

JSON requires double quotes for keys and string values. JavaScript object literals allow single quotes; JSON does not.

Typical error: Unexpected token ' in JSON at position …

Invalid
{
  name: "Alice",
  "age": 30
}
Fixed
{
  "name": "Alice",
  "age": 30
}

2. Trailing commas

No comma after the last property or array element. Editors may insert trailing commas that break strict JSON parsers.

ES2019+ JavaScript object/array literals allow trailing commas; the JSON spec (RFC 8259) never does.

Invalid
{
  "items": [1, 2, 3,],
  "tags": ["a", "b",]
}
Fixed
{
  "items": [1, 2, 3],
  "tags": ["a", "b"]
}

3. Unquoted keys

Every key must be a double-quoted string. { active: true } is invalid JSON.

{
  active: true,
  "score": 95
}

4. Missing or extra commas

Adjacent pairs need commas; duplicate commas trigger Unexpected token errors.

Missing comma
{
  "a": 1
  "b": 2
}
Extra comma
{
  "a": 1,, "b": 2
}

5. Bad escape sequences

Backslashes in paths must be doubled: \\ for each \. A lone backslash causes Bad escaped character.

Invalid
{ "path": "C:\Users\data" }
Fixed
{ "path": "C:\\Users\\data" }

6. NaN, Infinity, undefined

JSON only has null for emptiness—not JavaScript-only values like NaN or undefined.

{ "value": NaN }

7. Comments

JSON has no // or /* */ comments. Strip them before parsing.

Docs, VS Code JSONC, and JSON5 allow comments—they are not valid JSON.parse input. Exchange data as strict JSON.

{
  // user profile
  "name": "Bob"
}

8. Multiple top-level values or unclosed brackets

Valid JSON is one object or one array at the root. Missing } or ] yields Unexpected end of JSON input.

9. Invalid numbers

No leading zeros (007), no hex (0xFF), no lone decimal point.

10. Unescaped control characters

Newlines and tabs inside strings must be \n and \t—not literal line breaks copied from logs.

Try it online

Paste your text into the JSON tool. On failure, the sidebar shows the message and line number; the editor highlights that line.

After fixing, format or minify again—a success banner means the JSON is valid.