How to Fix “Unexpected Token” and Other Invalid JSON Errors
By the DocEpic team · Updated · 2 min read
“Unexpected token”, “Unexpected end of JSON input”, “is not valid JSON” — the error rarely says what is wrong, and a long JSON file on one line is impossible to read. Most mistakes are one of a handful, and they are quick to fix once you can see where they are.
Find the mistake
Paste the JSON into JSON Formatter. If it is valid, it is formatted with indentation. If it isn't, the message names the line and column and explains the problem, and the spot is selected in the box. Your JSON stays in your browser, so API keys and personal data aren't sent anywhere.
- Open JSON Formatter and paste the JSON.
- Read the message under the box: line, column and what's wrong.
- Fix that spot; the check runs again as you type.
- Copy the formatted JSON, or minify it for sending.
The usual mistakes and their fixes
JSON is stricter than JavaScript. These cause almost every error:
| Mistake | Wrong | Right |
|---|---|---|
| Comma after the last item | [1, 2, 3,] | [1, 2, 3] |
| Single quotes | {'name': 'Asha'} | {"name": "Asha"} |
| Key without quotes | {name: "Asha"} | {"name": "Asha"} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Comments | {"a": 1 // note} | {"a": 1} |
| Line break inside a text | "line one⏎line two" | "line one\nline two" |
| Missing bracket at the end | {"a": [1, 2} | {"a": [1, 2]} |
“Unexpected end of JSON input”
This means the text stops before the JSON is complete — usually an empty response from a server, or a file that was cut off. Check that the request actually returned something, and that the last bracket is there.
JSON to a spreadsheet and back
To read a JSON list of records as a table, use JSON to Excel & CSV. To make JSON from a spreadsheet, use Excel to JSON: numbers stay numbers and codes with a leading 0 stay text.
Questions people ask
Why does JSON need double quotes?
The JSON standard allows only double quotes for keys and texts. Single quotes work in JavaScript, but not in JSON.
Can JSON have comments?
No. Remove them, or keep notes in a separate field such as "_note".
Is it safe to paste API responses?
With JSON Formatter, yes: the text is checked in your browser and never sent to a server.