{}JSON FYI

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.

·6 min read

"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 key

5. 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 →

Frequently asked questions

What does 'Unexpected token u in JSON at position 0' mean?+

The first character is 'u', which starts the word 'undefined'. JavaScript's JSON.parse throws this when you pass undefined (not a string) — guard with a null check before parsing.

What does 'Unexpected end of JSON input' mean?+

The parser hit end-of-file before all brackets and quotes were closed. The JSON is truncated — check that the full response body was received.

Why does the error point to a closing bracket?+

A trailing comma before the bracket is the usual culprit. Remove the comma after the last value in the array or object.

Related tools & guides