How to Fix "JSON Parse Error: Unexpected EOF"

Published April 2025 · 4 min read

"Unexpected end of JSON input" means the JSON string is incomplete or empty.

1. Empty Response Body

// ❌ Parsing empty string
JSON.parse("") // Unexpected end of JSON input

// ✅ Check first
const data = response.text();
if (data) JSON.parse(data);

2. Truncated JSON

// ❌ Incomplete JSON
JSON.parse('{"name": "John", "age":')

// ✅ Make sure the full response is received

3. API Returned Non-JSON

// Check content-type header
const res = await fetch(url);
const contentType = res.headers.get('content-type');
if (contentType?.includes('application/json')) {
  const data = await res.json();
}

4. Network Timeout

The response was cut off due to timeout. Increase timeout or handle partial responses.

5. Server Returned Error Page

A 500 error might return HTML instead of JSON. Always check response status first:

const res = await fetch(url);
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();

Validate Your JSON

Use our JSON Formatter to check if your JSON is complete and valid.

Related