Input
- Size
- 0 B
- Lines
- 0
- Keys
- 0
- Depth
- 0
Why JSON.parse says unexpected token
JSON.parse reads one value. The first character it cannot accept is the unexpected token. Browsers phrase that differently. This page adds the line and column and selects that line in the input.
The response is HTML
An API sometimes returns a login page or a 500 page. The body starts with <!DOCTYPE html> or <html>. That is not JSON. Auto-Fix will not turn HTML into JSON. Open the network response and confirm the status code and content type before formatting the body.
A BOM or extra text
A file saved with a UTF-8 BOM can put an invisible character before {. Auto-Fix removes one leading BOM. Text after a complete JSON value, such as {"ok":true} thanks, is also an unexpected token. Delete the extra text. Only one JSON value is allowed.
JavaScript that is not JSON
Trailing commas, single quotes, comments, and unquoted keys are common in JavaScript and illegal in JSON. Auto-Fix rewrites those. The dedicated walkthrough is Fix trailing comma in JSON. Smart quotes copied from a document are still invalid; replace them with straight double quotes.
Frequently Asked Questions
What does JSON.parse unexpected token mean?
The parser found a character that cannot appear at that position. The status line names the line and column in the text you pasted.
Why does an API response fail JSON.parse?
The body is often an HTML error page, a proxy message, or extra text around the JSON. JSON.parse accepts one JSON value only.
Can a BOM cause unexpected token?
Yes. A leading byte-order mark before the first brace is not valid JSON. Auto-Fix strips one leading BOM and then parses again.
Does this validator upload my JSON?
No. Parsing, line and column reporting, and auto-fix all run in your browser.
Will Auto-Fix turn an HTML error page into JSON?
No. Auto-Fix repairs commas, comments, quotes, unquoted keys, and a leading BOM. An HTML page is still not JSON.