← All JSON guides

JSON guide · 6 min read

Unexpected Token in JSON: What It Means and How to Fix It

Understand unexpected token JSON errors, identify the character causing the failure and repair malformed API responses or files.

Published 2026-08-05Reviewed 2026-08-05

What the error means

An unexpected token error means the parser reached a character that is not legal at that position. The reported token is often only the point where parsing became impossible; the actual mistake may appear earlier.

Unexpected token <

A less-than sign often means the response is HTML rather than JSON. An API may have returned an error page, login page, proxy response or framework fallback document.

  • Inspect the HTTP status code before parsing.
  • Check the response Content-Type header.
  • Log the raw response body when debugging.

Unexpected token } or ]

A closing brace or bracket commonly indicates a trailing comma, a missing value or an object or array that was closed too early.

Invalid: {"name":"Ada",}
Valid:   {"name":"Ada"}

Unexpected token at position 0

Position 0 failures happen at the first character. Common causes include an empty response, HTML, a byte-order mark, plain text or a server error message being parsed as JSON.

How to find the exact problem

Paste the raw payload into the JSON Syntax Validator. Keep the payload unchanged at first, because formatting or copying selected fragments may hide the original error. After locating the failure, inspect several characters before and after the reported position.

Common questions

Frequently asked questions

Why does JSON.parse fail on an API response?

The response may be empty, malformed or not JSON at all. Verify the HTTP status, Content-Type and raw body before calling JSON.parse.

Is the reported token always the actual mistake?

Not always. A missing quote, comma or closing character earlier in the document can cause the parser to fail later.