format · validate · convert · runs locally

Fix "Unexpected end of JSON input"

The “Unexpected end of JSON input” error means the parser reached the end of the text while it was still waiting for more — a closing brace, bracket, or quote that never arrived.

The error

What causes it

The JSON is truncated or empty. Common causes: an empty string (JSON.parse("")), a response body that was cut off mid-transfer, a file that was only partially written, a missing closing } or ], or an unterminated string missing its closing quote. Reading a streamed response before it finished, or awaiting the wrong value, also produces an empty body.

How to fix it

First check that the input is non-empty — guard against parsing "" or undefined. Then confirm the whole payload arrived: compare the byte length you received against Content-Length, and make sure you awaited response.text() fully before parsing. Paste what you have into the validator below; it will point at where the document ends prematurely so you can add the missing brace, bracket, or quote.

Paste your JSON to find the problem

The validator below runs entirely in your browser and flags the exact line and column of the first error.

Frequently asked questions

Why do I get "Unexpected end of JSON input" on an empty string?

JSON.parse("") has nothing to parse, so it immediately hits the end of input. Guard with: if (text.trim()) JSON.parse(text). An empty API response (204, or a body you already consumed) is the usual source.

My JSON looks complete — why does it still fail?

A single missing closing } or ], or a string missing its closing quote, makes the parser run to the end still expecting more. Paste it into the validator below to see exactly where the structure is left open.

Could a truncated download cause this?

Yes. If the transfer was cut off, or you read a stream before it finished, the body ends mid-document. Verify the full payload arrived before parsing.