Unexpected token in JSON — causes and fixes
What 'Unexpected token' means, why it appears at different positions, and how to find and eliminate the offending character.
"Unexpected token" is the most common JSON parse error. It means the parser encountered a character it did not expect at that position — a mismatch between what the JSON grammar allows and what was in the input.
What the position tells you
Most parsers report a byte offset or line/column alongside the error. Three positions cover the vast majority of cases:
- Position 0 / line 1, col 1 — the very first byte is wrong. Common causes: empty string, an HTML error page returned instead of JSON, a UTF-8 BOM, or the literal string "undefined".
- Somewhere in the middle — the document started as valid JSON but something broke it: a trailing comma, single-quoted string, unquoted key, or an embedded comment.
- "Unexpected end of JSON input" — the parser hit end-of-file before all brackets and quotes were closed. The document is truncated.
Most common causes
1. Trailing comma
{ "a": 1, "b": 2, } // ✗ trailing comma before }
{ "a": 1, "b": 2 } // ✓2. Single-quoted string or key
{ 'name': 'Ada' } // ✗ single quotes are not JSON
{ "name": "Ada" } // ✓3. Unquoted key
{ name: "Ada" } // ✗ JavaScript object literal syntax
{ "name": "Ada" } // ✓4. JavaScript-style comment
{ "a": 1 // note } // ✗ comments are not valid JSON
{ "a": 1 } // ✓ — move notes to a sibling key5. Python-style literals
{ "ok": True, "x": None } // ✗ Python, not JSON
{ "ok": true, "x": null } // ✓6. Truncated response
Receiving only part of an HTTP response produces "Unexpected end of JSON input". Check Content-Length headers, network errors, and streaming-read logic that might stop early.
How to locate and fix the error
Paste the JSON into the validator. The error panel shows the exact line, column, and a hint pointing at the invalid token.
Paste your JSON into the validator →
Get the exact line, column, and a fix hint in seconds — no upload, no signup.
Open JSON Validator →