How browsers word it
| Chrome and Node (V8) | Unexpected end of JSON input |
|---|---|
| Firefox | JSON.parse: unexpected end of data at line 1 column 1 of the JSON data |
| Safari | JSON Parse error: Unexpected EOF |
Common causes
The body is empty
A 204 No Content response, a failed request or a missing file gives an empty string, and parsing an empty string always fails.
Input
(empty)
JSON Formatter says
Nothing to parse. The input is empty
The text is only whitespace
A body that holds just a newline or spaces fails the same way.
Input
JSON Formatter says
Nothing to parse. The input is empty
The text was cut off where a value should be
A dropped connection, a size limit or a file that was not saved completely can stop the text right after a colon or a comma.
Input
{"a":JSON Formatter says
Unexpected end of input. A value is missing
The text was cut off inside a string
If the cut falls inside a string, current engines report an unterminated string rather than this message.
Input
{"a": "helJSON Formatter says
Unterminated string. A closing double quote is missing
How to fix it
- Log the raw response text and its length before parsing.
- Check the status code. A 204 has no body, so skip .json() for it.
- Compare Content-Length with what you received, and look for proxies or functions that limit the response size.
- If you read a file, make sure it was written completely before it is parsed.