unexpected end of input 🟨 JavaScript

SyntaxError: Unexpected end of input

The parser reached the end of the code (or JSON) while still expecting more — a missing } ) ] or empty JSON.

Seen on: JavaScript

Meaning

For code: an unclosed brace or bracket. For JSON.parse/response.json(): the body was empty.

Common causes

  • Missing closing } or )
  • Unterminated template literal
  • Empty response passed to JSON.parse

⚡ Quick fix

  1. Use an editor with bracket matching / run a linter
  2. Check response.status and length before .json()

Detailed fix by platform

JavaScript

  1. const text = await res.text(); const data = text ? JSON.parse(text) : null;

How to diagnose

  1. Source — Code or JSON parsing?
  2. Balance — Are brackets balanced?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.