formatjson.pro
Validate, pretty-print or minify JSON in your browser — nothing is uploaded.

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.

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.