JSON parse error: what it means and how to fix it
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
A JSON parse error means a program received text that was supposed to be JSON and could not read it. There are three kinds of causes: the text is empty, it is not JSON at all (often an HTML page), or the JSON has a syntax error. Below is how to tell which one you have and what to do.
What JSON parse error means
Parse means read and convert. The program reads the text character by character and builds an object. As soon as it meets something JSON cannot contain, parsing stops with an error. The message usually includes the position or line where it happened, and that is the main clue.
Three kinds of causes
Empty text: the server returned nothing or the file is empty, hence The document is empty and Unexpected end of JSON input. Not JSON: an HTML error or login page arrived, hence Unexpected token with a less-than sign at the start. Broken JSON: single quotes, a trailing comma, a comment, a truncated response.

If someone else's app shows the error
If you see a JSON parse error in an app, a game or a website rather than your own code, the service usually returned an empty response or an error page. Retry later, check your connection and VPN, update the app, and for desktop programs delete the corrupted settings file so the program recreates it.
How to avoid it in your code
Check the status code and content type before parsing, handle an empty body separately and put the start of the received text into the error message. Instead of a cryptic JSON parse error, the log then shows that a 502 page or an empty response arrived.

How the error looks in different languages
| Where | Message | Usually means |
|---|---|---|
| JavaScript | Unexpected token < in JSON at position 0 | HTML arrived instead of JSON |
| JavaScript | Unexpected end of JSON input | Empty or truncated response |
| Python | JSONDecodeError: Expecting value: line 1 column 1 | Empty or not JSON from the first character |
| Java, Jackson | JsonParseException: Unexpected character | An invalid character in the text |
| 1C | Unexpected character when reading JSON | HTML, BOM or empty body |
| Apps | The document is empty, Failed to parse JSON config | Empty response or corrupted settings file |
Specific cases: Unexpected token, Unexpected end of JSON input, DOCTYPE is not valid JSON, the 1C error.
How to find the spot
- Look at the position or line and column in the message; the mistake is usually just left of it.
- Paste the text into a JSON validator: it shows the spot and the likely cause.
- If the first character is <, it is HTML: check the status code and the request URL, not the JSON.
- If the text is empty, there is nothing to parse: find out why the service or file returned nothing.
Protecting your code
const res = await fetch(url);
const text = await res.text();
if (!text.trim()) throw new Error(`Empty response, status ${res.status}`);
try {
return JSON.parse(text);
} catch (e) {
throw new Error(`JSON parse error: ${e.message}. Status ${res.status}, start: ${text.slice(0, 200)}`);
}Such a handler turns a cryptic parse error into a message with the status code and the start of the text. The cause is visible at a glance.
More on JSON
Section overview and all guides: JSON: what the format is, syntax rules, examples and common errors.
Frequently asked questions
What does JSON parse error mean?
A program received text it had to read as JSON and could not. Usually the text is empty, an HTML page, or has a syntax error.
What does parse mean here?
Reading text and turning it into an object.
What if an app shows JSON parse error?
The service failed or a settings file is corrupted. Retry later, check the connection and VPN, update the app or delete the corrupted settings file.
Repeat this on your own API
Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.
Download FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.