SyntaxError: Unexpected end of JSON input
The parser reached the end of the string before the value was complete. The three causes: you parsed an empty string (JSON.parse('') throws this), the response was truncated, or a closing } or ] is missing. Check for an empty body first — it is the most common one.
Runs entirely in your browser — your JSON is never uploaded to a server. No ads injected into the output, no sign-up, and the repair logic is tuned for this exact error rather than generic pretty-printing.
How to fix "Unexpected end of JSON input"
- Check for an empty response. This error means the parser reached the end of the string before the JSON was complete. Most often the input is an empty string "" — a fetch that returned no body (204 No Content or a failed request).
- Look for a truncated payload. If the input is not empty, a closing } or ] is missing, usually because the response was cut off mid-stream. Paste it into the tool above; Repair closes unbalanced brackets.
- Guard before parsing. Wrap JSON.parse in a check: only parse when the response body is non-empty and response.ok is true.
What the error means
JSON was well-formed up to the point where the input ran out. Unlike "Unexpected token", the characters seen were valid — there just weren't enough of them to finish the value.
The three causes
1. Empty or whitespace-only string. JSON.parse('') and JSON.parse(undefined) both throw this. Guard with if (!text) return null; before parsing, and check that your fetch actually returned a body (a 204 No Content has none).
2. Truncated response. A dropped connection, a stream read before it finished, or a response-size limit cuts the JSON mid-way. Log the length and the last 50 characters.
3. Unclosed bracket. A missing } or ] means the parser is still waiting for more when the string ends. Count your opening and closing brackets.
Fix it fast
Paste the fragment above and hit Repair to close open brackets and see the completed structure. For empty or truncated bodies the fix is upstream: make sure the request completes and returns content.
FAQ
Why does JSON.parse('') throw this?
An empty string contains no value at all, so the parser hits end-of-input immediately. Always check for an empty body before parsing.
My JSON looks complete — why still the error?
An earlier bracket is probably unclosed, so the parser expects more input. Count { vs } and [ vs ], or paste it into the tool to locate the imbalance.
Could it be a streaming/async issue?
Yes. Reading the body before the stream finishes gives you a partial string. Await the full response (res.text() / res.json()) before parsing.