Error Reference › JavaScript
JavaScript
Unexpected end of JSON input
JSON.parse got an empty or truncated string — there was nothing (or not enough) to parse.
What it looks like
Uncaught (in promise) SyntaxError: Unexpected end of JSON input
What does "Unexpected end of JSON input" mean?
Thrown by JSON.parse or response.json() when the text is empty or cut off. The most common trigger is calling .json() on a response with no body — a 204 No Content, an error response, or a request that failed.
What causes "Unexpected end of JSON input"?
- An empty response body.
- A failed fetch that returned no JSON.
- Truncated/cut-off data.
How do I confirm the cause?
- Log the response status and await response.text() before parsing to see what actually arrived.
- Check for a 204 or an error status: many servers return an empty body in those cases.
- If the text looks truncated, check for a proxy, size limit or server crash cutting the response short.
How do I fix "Unexpected end of JSON input"?
- Check the response is non-empty before parsing (res.ok, status).
- Log the raw text before JSON.parse.
- Handle the empty case explicitly.
How do I stop it happening again?
- Only parse JSON when the status is 200-299 and the body is non-empty.
- Make your own APIs always return a JSON body, even for errors ({"error": "…"}).
- Wrap parsing in try/catch and show a clear message, so one bad response cannot break the whole page.