Fix "Unexpected end of JSON input"
JavaScript / Node.js ยท JSON error
Opens the editor with a broken example loaded and repaired, entirely in your browser โ nothing is uploaded.
What causes it
This error means the parser ran out of input before the document was complete. There are three common causes:
- An empty string. Calling
JSON.parse('')throws immediately. This happens when afetchreturns a204 No Content, a failed request, or a body you already consumed once. - A truncated response. The connection dropped or the server cut the body short, so the closing
}or]never arrived. - A genuinely unbalanced document โ a missing closing brace, bracket, or quote that you can fix by hand.
How to fix it
- Check the response is not empty and the status is not 204 before parsing.
- Guard with: const text = await res.text(); const data = text ? JSON.parse(text) : null.
- If the body is truncated, look for a network timeout or a server that streamed an incomplete response.
- Paste the text into JSON Wallet โ the tree view shows exactly which bracket or quote is left unclosed, and Repair can balance it.
Before and after
Broken:
{
"id": 1,
"tags": ["a", "b"Fixed:
{
"id": 1,
"tags": ["a", "b"]
}Want to fix your own JSON instead of the example? Open the editor, paste it in, and click Repair โ it runs entirely in your browser.
Frequently asked questions
Why does an empty response cause this error?
JSON.parse('') has nothing to parse, so it fails at the end of input. Always check for an empty body (for example a 204 status) before parsing.
How do I find the missing bracket?
Paste the JSON into the editor and switch to tree view. The branch that never closes will fail to render, pointing you straight at the unbalanced structure.
Related JSON errors
Fix "Unexpected token in JSON at position N"
The most common JSON.parse() error. It means the parser hit a character it did not expect โ usually HTML, an already-parsed object, or a stray token.
Fix "Unexpected non-whitespace character after JSON"
The parser finished reading one valid JSON value and then found more text. Usually two objects concatenated together, or newline-delimited JSON.
For a full reference of JSON mistakes, read Common JSON errors and how to fix them.