Why it happens
Three causes cover almost every case.
1. The body is empty. JSON.parse('') throws this exact error. You get an empty string from a 204 No Content response, a HEAD request, a server error with no body, or a file that exists but has nothing in it. In Firefox the position gives it away: line 1, column 1.
2. The JSON was cut off. The text starts correctly and stops partway, like the sample in the checker above. Typical sources:
- a network response that closed early, or a proxy with a body size limit
- a log line or database column shorter than the value (a
VARCHAR(255)holding a 300-character document) - an LLM reply that hit its token limit mid-object
- a copy and paste that missed the last line
3. A bracket is missing. Hand-edited JSON with an unclosed { or [ runs out of text before the parser finds the closer. The checker names the bracket and the line it opened on.
How to fix it
fetch
Check the status and read the body as text before parsing, so an empty body becomes a clear decision instead of an exception:
const res = await fetch('/api/orders/1042');
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
const text = await res.text();
const order = text ? JSON.parse(text) : null; // 204 or empty body
res.json() is fine when the endpoint always returns a body. Use the pattern above for endpoints that can answer 204.
axios
axios parses JSON for you. An empty body arrives as response.data === '' instead of throwing, so the error usually shows up later when you call JSON.parse(response.data) yourself. Drop the manual parse, or guard it with the same empty check.
Node.js files
JSON.parse(fs.readFileSync('config.json', 'utf8')) throws this when the file is empty or another process is still writing it. Write to a temporary file and rename it when done, so readers never see a half-written file.
Truncated text from a model or a stream
Ask for less output, raise the token limit, or stream and parse only after the final chunk arrives. To salvage what you have, paste it into JSON Repair, which closes the open structures. Check the result: whatever was cut off is still gone.
A missing bracket
Paste the JSON into the checker above or the JSON validator. It reports Unexpected end of input: 1 bracket never closed and highlights where that bracket opened, which is faster than counting braces by eye.
Same error in other languages
- Python: an empty string raises
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0). See JSONDecodeError: Expecting value. - Go:
json.Unmarshalon an empty or truncated[]bytereturnsunexpected end of JSON input, word for word. - Unclosed string: text cut off inside a string gives Unterminated string in JSON in Chrome instead.
For the other errors JSON parsers throw, see common JSON errors.