Unexpected end of JSON input — causes and fixes
Why 'Unexpected end of JSON input' appears, the four most common root causes, and how to find the missing bracket or quote that truncated your document.
"Unexpected end of JSON input" (or "Unexpected end of data") means the JSON parser hit end-of-file before all open brackets, braces, or quotes were closed. The document is incomplete — truncated somewhere.
The four most common causes
1. Truncated HTTP response
If a streaming connection drops, a read is cancelled early, or the server crashes mid-response, you receive a partial JSON body. The parser reads up to the last byte and then hits EOF with structure still open.
// Axios / fetch may silently give you a partial body
// Always check Content-Length vs actual body length
const res = await fetch(url);
const text = await res.text();
console.log('body length:', text.length);
console.log('last chars:', JSON.stringify(text.slice(-20)));2. Missing closing bracket or brace
The most common hand-editing mistake — you add a new nested object or array and forget the matching } or ] at the end.
{
"users": [
{ "id": 1, "name": "Ada" }
]
// ✗ missing closing } for the root object3. Empty or nearly-empty string
JSON.parse(""), " and ", JSON.parse(" "), " both throw 'Unexpected end of JSON input' because there is no value to parse. Guard before calling parse:
const data = text?.trim() ? JSON.parse(text) : null;
4. Unterminated string
A string that starts with a quote but never closes also produces this error because the parser keeps reading until EOF waiting for the closing quote.
{ "message": "Hello, world // ✗ no closing quoteHow to find the truncation point
- Paste the JSON into the validator — it reports the byte offset of the last valid character before EOF.
- Check
text.lengthagainst the response'sContent-Lengthheader. - Look at the last ~20 characters:
text.slice(-20). If they're mid-value, mid-string, or there are no closing brackets, truncation happened.
Paste your JSON into the validator →
Get the exact line, column, and a fix hint in seconds — no upload, no signup.
Open JSON Validator →