Fix JSON Unexpected Token Errors
Unexpected token means a strict JSON parser reached a character that cannot appear at that position in valid JSON.
What "Unexpected token" Means
A JSON parser reads the document from left to right against the RFC 8259 grammar. When it reports Unexpected token, it found a character that doesn't match what's legal at that position. The reported character is a clue, but the real mistake is often the character just before it — a missing comma, an unescaped quote, or an unclosed brace.
Token-by-Token Lookup
The token in the error message usually points to one of these specific causes. Find your token in the first column; the third column links to the dedicated deep-dive.
| Token | What it means | Deep dive |
|---|---|---|
' |
A single-quoted string or key. JSON requires double quotes. | JSON.parse Unexpected Token overview |
, |
A trailing comma — JSON forbids them. | Fix trailing commas in JSON |
/ or // or /* |
A JavaScript-style comment. JSON has no comments. | JSON.parse Unexpected Token overview |
T, F, N |
Python-style True / False / None. JSON uses true / false / null. |
JSON.parse Unexpected Token overview |
< (at position 0) |
The response is HTML, not JSON — usually a 404 page or login redirect. | Unexpected token < — you got HTML |
o (at position 1) |
You parsed "[object Object]" — something stringified an object before serializing. |
Unexpected token o at position 1 |
u (at position 0) |
You parsed the literal string "undefined". |
Unexpected token u — undefined |
\ |
An invalid escape sequence inside a string. | Bad escaped character in JSON |
| (end of input) | The response was truncated before the closing brace or bracket. | Unexpected end of JSON input |
| "after JSON value" | Extra text appears after a complete JSON document. | JSON.parse Unexpected Token overview |
Broken Example
A single payload that combines several of the variants above — each line is rejected for a different reason:
{
name: 'Ada', // unquoted key + single-quoted string
active: True, // Python-style boolean
/* tags */ // JavaScript comment
tags: ['dev',], // trailing comma
}
Fixed JSON
The same data, expressed as strict JSON:
{
"name": "Ada",
"active": true,
"tags": ["dev"]
}
Keys and strings are double-quoted, True becomes true, the comment is dropped, and the trailing comma is removed.
Repair Workflow
- Read the parser's error message in full. It reports the line and column of the unexpected token — write them down before guessing.
- Look one character before the reported token. The "Unexpected token" is what the parser couldn't accept; the real bug is usually the character (or missing character) just before it — a missing comma between items, an unescaped quote inside a string, an unclosed brace.
- Auto-repair with JSON Fix. The tool handles the common variants — single quotes, trailing commas, unquoted keys, Python
True/False/None, line and block comments — in one pass, in your browser. - Re-validate against strict JSON with the strict JSON validator to confirm the result conforms to RFC 8259. Auto-repair fixes the common mistakes; strict validation confirms nothing else is wrong.
- If errors remain, use the token-lookup table above to identify the variant, then open the matching deep-dive for that specific case (HTML response,
[object Object],undefined, bad escape, end-of-input). - For repeat occurrences in one workflow — LLM output, an API client, log-line parsing — see the LLM JSON repair hub for prevention patterns that stop the error at the source.
Related Deep Dives
Each of these covers one specific Unexpected token variant in depth, with broken/fixed examples and step-by-step fixes:
- How to Fix
JSON.parseUnexpected Token Errors (overview) — every token variant mapped in one place - Unexpected token
<in JSON at position 0 — you received HTML, not JSON - Unexpected token
oin JSON at position 1 — you parsed"[object Object]" - Unexpected token
uin JSON at position 0 — you parsed the literal"undefined" - Unexpected end of JSON input — the response was cut short
- Bad escaped character in JSON — invalid
\escape sequence inside a string
See also
This guide covers one common parser error. The hub maps every JSON parser error message to the article that explains it.
Sources
- RFC 8259 — the JSON Data Interchange Format (IETF, the canonical JSON grammar)
- ECMA-404 — the JSON Data Interchange Syntax (Ecma International, the parallel JSON spec)
- MDN —
JSON.parse(the parser that emits these errors)
Last reviewed June 2026.
JSON repair guides
Topic hubs
- JSON Parse Errors: Read the Message, Jump to the Fix
- Fix Invalid JSON: From 'What's Wrong' to a Clean File
- JSON Formatter, Validator, Viewer: Pick the Right Tool
- Repair LLM JSON Output: Handling Almost-JSON from AI
- Privacy: JSON Tools That Don't Leave Your Browser
- JSON Interop: YAML, CSV, XML, JWT, Schema
Specific guides
- How to Decode Base64 Strings (and JWT Payloads)
- URL Encoding: Percent-Encode Query Parameters and Paths
- Convert YAML to JSON (and Avoid Indentation Errors)
- Convert JSON to CSV: Flatten an Array of Objects
- Convert JSON to XML: Root Elements, Attributes, and Arrays
- Escape JSON as a String Literal (and Decode Double-Encoded JSON)
- Fix Trailing Comma in JSON
- Fix Single Quotes in JSON
- Fix Unquoted Keys in JSON
- Repair LLM JSON Output
- Fix JSON Parse Error: Expected Property Name
- JSON vs JS Object Literal: The Key Differences
- Validate JSON Before API Requests
- JSON Formatter vs JSON Repair
- JSON to JavaScript Object Converter