format · validate · convert · runs locally

Fix "Unexpected token in JSON"

The “Unexpected token … in JSON” error means the parser hit a character it did not expect for valid JSON. It is one of the most common errors from JSON.parse(), response.json(), and fetch.

The error

What causes it

Almost always, the text you are parsing is not JSON at all. Unexpected token < in JSON at position 0 is the classic tell: the very first character is <, so you are parsing an HTML page (a login redirect, a 404, or a server error page) instead of a JSON response. Other variants — Unexpected token o (the word [object Object]), a stray letter, or a leading byte-order mark — mean a stray or wrong character is sitting where JSON syntax expected a value.

How to fix it

Log the raw response body before parsing and look at the first characters. If it starts with <!DOCTYPE or <html>, fix the request (wrong URL, auth redirect, or an error status) rather than the JSON. If it is genuine JSON with one bad character — a smart quote, a trailing comma, an unquoted key, or a leading BOM — paste it into the validator below to jump straight to the offending line and column.

Paste your JSON to find the problem

The validator below runs entirely in your browser and flags the exact line and column of the first error.

Frequently asked questions

What does "Unexpected token < in JSON at position 0" mean?

Position 0 is the first character. A < there means the response is HTML, not JSON — usually an error page, a redirect to a login screen, or a 404 returned where you expected JSON. Inspect the raw response and fix the request.

What does "Unexpected token o in JSON at position 1" mean?

You very likely called JSON.parse on a value that is already a JavaScript object. Coercing it to a string yields "[object Object]", and the parser trips on the o at position 1. Do not JSON.parse something that is already parsed.

How do I find the exact bad character?

Paste the JSON into the validator on this page — it reports the precise line and column of the first unexpected token so you can delete or fix that character.