{}JSON FYI

Unexpected end of JSON input — causes and fixes

Why 'Unexpected end of JSON input' appears, the four most common root causes, and how to find the missing bracket or quote that truncated your document.

·5 min read

"Unexpected end of JSON input" (or "Unexpected end of data") means the JSON parser hit end-of-file before all open brackets, braces, or quotes were closed. The document is incomplete — truncated somewhere.

The four most common causes

1. Truncated HTTP response

If a streaming connection drops, a read is cancelled early, or the server crashes mid-response, you receive a partial JSON body. The parser reads up to the last byte and then hits EOF with structure still open.

// Axios / fetch may silently give you a partial body
// Always check Content-Length vs actual body length
const res = await fetch(url);
const text = await res.text();
console.log('body length:', text.length);
console.log('last chars:', JSON.stringify(text.slice(-20)));

2. Missing closing bracket or brace

The most common hand-editing mistake — you add a new nested object or array and forget the matching } or ] at the end.

{
  "users": [
    { "id": 1, "name": "Ada" }
  ]
  // ✗ missing closing } for the root object

3. Empty or nearly-empty string

JSON.parse(""), " and ", JSON.parse(" "), " both throw 'Unexpected end of JSON input' because there is no value to parse. Guard before calling parse:

const data = text?.trim() ? JSON.parse(text) : null;

4. Unterminated string

A string that starts with a quote but never closes also produces this error because the parser keeps reading until EOF waiting for the closing quote.

{ "message": "Hello, world   // ✗ no closing quote

How to find the truncation point

  • Paste the JSON into the validator — it reports the byte offset of the last valid character before EOF.
  • Check text.length against the response's Content-Length header.
  • Look at the last ~20 characters: text.slice(-20). If they're mid-value, mid-string, or there are no closing brackets, truncation happened.

Paste your JSON into the validator →

Get the exact line, column, and a fix hint in seconds — no upload, no signup.

Open JSON Validator →

Frequently asked questions

Is there a difference between 'Unexpected end of JSON input' and 'Unexpected end of data'?+

They're the same error from different engines. V8 (Chrome/Node) says 'Unexpected end of JSON input'; Safari's JavaScriptCore says 'Unexpected end of data'. Both mean the parser hit EOF before the document was complete.

Could it be a BOM causing the end-of-input error?+

Unlikely for this specific error — a BOM at the start causes 'Unexpected token' errors, not end-of-input. End-of-input means the document ran out of characters, not that it started wrong.

What if the JSON looks complete but the error still fires?+

Check for invisible characters or a null byte (\u0000) embedded in the string — some parsers treat those as end-of-input. Use text.indexOf('\u0000') to check.

Related tools & guides