Unexpected end of JSON input
The parser reached the end of the input while it still expected more. Either the string was empty to begin with, or a value was left open and the document was truncated. Note that this message carries no position, which is what distinguishes it from the errors that do.
Paste your JSON and see exactly where it breaks
Nothing you paste leaves your browser. The connect-src allowlist makes that a browser guarantee rather than a promise. Check it yourself
What actually causes it
Ranked by how often each one turns out to be the answer.
-
01 The string is empty
JSON.parse("") throws this immediately. An empty string is not valid JSON. This usually comes from an HTTP 204, a response with no body, or a localStorage key that was written as an empty string.
Breaks
JSON.parse(localStorage.getItem('draft'))Works
const raw = localStorage.getItem('draft'); const draft = raw ? JSON.parse(raw) : null; -
02 The response body was already consumed
A Response body can only be read once. Calling res.text() and then res.json() on the same response gives you an empty string the second time.
Breaks
const text = await res.text(); const data = await res.json(); // body already usedWorks
const text = await res.text(); const data = text ? JSON.parse(text) : null; -
03 The document is truncated
A dropped connection, a body-size limit (Express defaults to 100kb), a stream read that finished early, or a file that was written while being read. If the input ends mid-object, our validator names every bracket that was left open and where each one started.
Breaks
{"users": [{"id": 1}, {"id":Works
{"users": [{"id": 1}, {"id": 2}]} -
04 The npm or yarn cache is corrupt
A large share of searches for this string are about npm rather than about application code. A partially written cache file produces the same error during install. Run npm cache clean --force, delete node_modules and package-lock.json, and install again.
-
05 You parsed the result of a function that returned nothing
JSON.parse(undefined) gives a different message ("undefined" is not valid JSON), but a function returning an empty string rather than undefined lands here.
The same mistake in other runtimes
The underlying problem is identical; only the wording differs. If a colleague reports one of these, they are looking at the same thing you are.
| Python | Expecting value: line 1 column 1 (char 0) |
|---|---|
| Python, truncated object | Expecting ',' delimiter: line 1 column 28 (char 27) |
Questions
- Why is there no line or column in this message?
- Because there is no position to point at. The failure is that the input ended, so the offending location is the end of the document. Our validator reports it as end of input and lists which brackets were still open.
- Does JSON.parse(null) throw this?
- No. JSON.parse(null) coerces null to the string "null" and returns null, which surprises people. The empty string is what throws.
Fix it now
Paste the payload into the tool above, or go straight to the one built for this job.
Find the unclosed bracket