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 uundefined
\ 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

  1. Read the parser's error message in full. It reports the line and column of the unexpected token — write them down before guessing.
  2. 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.
  3. 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.
  4. 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.
  5. 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).
  6. 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:

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.