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.
Unexpected end of JSON inputUnexpected end of inputUnterminated string in JSONThe 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.
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.
The validator below runs entirely in your browser and flags the exact line and column of the first error.
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.
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.
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.