JSON Forge
100% Client-Side: your data is never sent to a server

JSON errors

Unexpected end of JSON input

The JSON below reproduces this error. See where it breaks, press Fix JSON, or paste your own text.

Loading editor…
Paste or type JSON on the left to explore it as a tree.
Empty🔒 Processed locally in your browser

What the error means

The parser reached the end of the text while it still expected more: a closing bracket, a value after a colon, or any value at all. Either the text is empty, or it was cut off before the JSON was complete.

The message looks like this in Chrome, Edge and Node.js (Firefox and Safari use different wording for the same problems):

Unexpected end of JSON input
Expected ',' or ']' after array element in JSON at position 29 (line 1 column 30)

Common causes

The response body is empty

A 204 No Content response, a request that failed in the network layer, or an API that returns nothing for "not found" all give an empty string. JSON.parse("") fails with exactly this message.

Broken:  (empty text)
Valid:   null

The JSON was cut off

Proxies with size limits, a crashed server that sent only part of the body, or a file that was not fully written leave a document that stops in the middle. Newer Chrome versions then name the missing piece, for example an expected comma or closing bracket.

Broken:  {"name": "Ada", "tags": ["math", "code"
Valid:   {"name": "Ada", "tags": ["math", "code"]}

You parse a value that was never saved

Reading a key from localStorage that holds an empty string, or a file that was created but not written yet, gives empty text.

The body was already consumed

Calling res.json() after res.text() throws a different error, but code that reads the body in a middleware and then again can end up with an empty string.

How to find the problem

  1. Paste the text that you passed to JSON.parse into the editor above. The status bar shows the line and column of the first problem, and Go to error jumps there.
  2. Remember that the position in the message is where the parser gave up, which is often one token after the real mistake. Look at the character before it as well.
  3. If the text came from a request, log the raw response text before parsing it. In the browser, open the Network tab, select the request and read the Response tab.

Parse empty or missing input safely

function parseJson(text, fallback = null) {
  if (typeof text !== "string" || text.trim() === "") return fallback;
  try {
    return JSON.parse(text);
  } catch (err) {
    console.error("Invalid JSON:", err.message, text.slice(0, 200));
    return fallback;
  }
}

const res = await fetch(url);
const data = res.status === 204 ? null : parseJson(await res.text());

Frequently asked questions

How do I know whether it is empty or truncated?

Log the text length and the last 100 characters before parsing. Zero length means empty. Text that ends mid-structure means it was cut off.

Can Fix JSON repair truncated JSON?

It can often close the missing brackets, which is useful to inspect what you received. It cannot recover data that never arrived, so fix the cause as well.

Related errors

All common JSON errors · JSON Validator