SyntaxError: Unexpected end of JSON input means the parser reached the end of the text while it still expected more: a closing bracket, a value, or anything at all. The JSON is either empty or cut off.
The example above stops in the middle of an object, as happens when a log line or response is truncated. Press Fix and the open brackets are closed.
Example
{
"id": 42,
"items": [
{"sku": "A1", "qty": 2},
{"sku": "B7", "qty"{
"id": 42,
"items": [
{
"sku": "A1",
"qty": 2
},
{
"sku": "B7",
"qty": null
}
]
}Common causes
- An empty response body, for example from a
204 No Contentresponse or a failed request, passed toJSON.parseorresponse.json(). - Data cut off by a log length limit, a terminal, a database column size or a copy that missed the end.
- A stream or file read before it finished writing.
- An unclosed
{,[or string while editing by hand.
How auto-fix completes truncated JSON
Auto-fix closes every open string, object and array. If the text ends right after a key, the missing value becomes null, as with "qty" in the example. Data that was never there cannot be recovered, so review the end of the result before you rely on it.
Fixing it at the source
In JavaScript, check response.ok and the status code before calling response.json(), and read the body with response.text() first if it might be empty. For logs, raise the line length limit or log the payload separately.
Frequently asked questions
Why do I get this error on an empty string?
An empty string is not valid JSON. JSON.parse("") throws "Unexpected end of JSON input" because there is no value at all.
Can the missing data be recovered?
No. Auto-fix makes the JSON valid by closing what was opened, but anything after the cut is gone. Get the full data from the source if you need it.