JSON Parse Error Fixes

If you are seeing failed to parse JSON or unexpected token, use this guide to identify the error type and apply a quick fix in minutes.

Top JSON parse errors and what they mean

Unexpected token < in JSON at position 0
Usually means: HTML response was parsed as JSON (often a 404/500 page).
Quick fix: Check response status, URL, and Content-Type before JSON.parse.
Unexpected token ' in JSON
Usually means: Single quotes used in JSON keys or strings.
Quick fix: Use double quotes for all keys and string values.
Unexpected token } or ]
Usually means: Trailing comma or broken object/array structure.
Quick fix: Remove trailing commas and validate bracket/brace nesting.
Unexpected end of JSON input
Usually means: Truncated body or empty payload.
Quick fix: Inspect raw response and ensure complete output before parsing.
Unexpected number / string
Usually means: Missing comma between adjacent values.
Quick fix: Insert commas between fields or array values.

Step-by-step debugging workflow

  1. Log raw payload before parsing.
  2. Check HTTP status and response headers.
  3. Validate JSON syntax in a formatter/validator.
  4. Fix quotes, commas, brackets, and escaped characters.
  5. Re-run parser and add input guards for future payloads.

Bad → fixed examples

// Bad (single quotes, trailing comma)
{ 'name': 'Kim', 'role': 'engineer', }

// Fixed
{ "name": "Kim", "role": "engineer" }

// Bad (unescaped newline)
{ "message": "line 1
line 2" }

// Fixed
{ "message": "line 1
line 2" }