How to Fix "Unexpected end of JSON input"
Updated
SyntaxError: Unexpected end of JSON input means the parser ran out of characters before the document was complete. Unlike "unexpected token", nothing in the text is wrong — something is missing from the end.
There are only three realistic causes, and each has a distinct fix.
Cause 1: You parsed an empty string
JSON.parse("") throws exactly this error, and it is by far the most common cause in application code. Typical scenarios: an API returned 204 No Content or an empty body, a fetch response was consumed twice (the second .json() call sees an empty stream), or a variable you assumed held JSON was never assigned.
Fix: check the response status and body before parsing. If the body can legitimately be empty, guard for it.
const text = await response.text();
const data = text ? JSON.parse(text) : null;Cause 2: The document was truncated
Copy-pasting from a terminal, log viewer, or chat window often silently cuts off long payloads. Network timeouts and size limits do the same to responses. The JSON starts out fine and simply stops mid-value.
Fix: re-copy the full payload from the original source. If it came over the network, check for a Content-Length mismatch or a proxy/body-size limit that clipped the response.
Cause 3: A missing closing brace or bracket
If you edited the JSON by hand, the likely culprit is an unbalanced { or [. Every opening brace and bracket needs a closing partner, and in a deeply nested document the missing one is hard to spot by eye.
Fix: paste the document into the validator and click Beautify once it parses — or, while it doesn't, use the reported line and column. Properly indented output makes an unclosed container obvious: everything after it stays indented one level too deep.
{
"user": {
"id": 42
}{
"user": {
"id": 42
}
}Try it now
Paste your JSON into the free toolkit — validate, beautify, minify, and explore it without your data ever leaving the browser.
Open the JSON ToolkitFrequently asked questions
Why does JSON.parse("") throw "Unexpected end of JSON input"?
An empty string contains no JSON value at all, so the parser reaches the end of input before finding anything to parse. Guard against empty bodies before calling JSON.parse.
How do I find a missing bracket in a large JSON file?
Paste it into a validator with line/column reporting. Fix the reported location, then beautify: consistent indentation makes any remaining unbalanced braces or brackets visually obvious.
Is "Unexpected end of JSON input" the same as "Unexpected token"?
No. "Unexpected token" means an illegal character appears somewhere in the document. "Unexpected end of JSON input" means the document ends too early — the text that exists is fine, but the rest is missing.