curly{bits}

curlybits / JSON Formatter / JSON Errors Explained

JSON Errors Explained

Paste the JSON that fails and see where it breaks and what the error means in plain English. Below are the error messages you'll see in Chrome, Node.js, Firefox, Safari and Python, what causes each one, and how to fix it.

Input JSON
Formatted output

      

JSON Errors Explained: step by step

  1. Paste the JSON that gives the error.
  2. The exact line and column are highlighted, with an explanation of what's wrong.
  3. Click 🔧 Fix it for common mistakes, or fix the spot by hand.
  4. If your code fetched the data, look at the section for your error message below.

“Unexpected end of JSON input”

The parser reached the end of the text while it was still expecting more. Two causes cover almost every case:

  • The response was empty. await response.json() on a 204 No Content reply, a failed request, or a server error with no body. Check response.status and read response.text() first if you're not sure there's a body.
  • The JSON was cut off. A closing }, ] or " is missing, often because a log line or a copy was truncated. Paste it above to see what's still open.
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const text = await res.text();
const data = text ? JSON.parse(text) : null;

Firefox says “JSON.parse: unexpected end of data” and Safari “JSON Parse error: Unexpected EOF”.

“Unexpected token < in JSON at position 0” / “… is not valid JSON”

The first character is <, so the server sent HTML, not JSON. Typical reasons: a wrong URL that returns a 404 page, an expired login that redirects to a sign-in page, a server error page, or a development server returning index.html for an unknown API route. Newer Chrome and Node.js versions say Unexpected token '<', "<!DOCTYPE "... is not valid JSON. Open the request in the Network tab of your browser's developer tools to see what actually came back.

Other “unexpected token” letters point to other causes: u means the text was undefined, o often means [object Object] (an object was turned into a string instead of using JSON.stringify), and ' means single quotes.

“Expected double-quoted property name”

A key isn't in double quotes, as in {name: "Aung"} or {'name': "Aung"}, or there's a trailing comma before }: {"a": 1,}. JSON needs {"name": "Aung"} with no comma after the last item. Firefox says “expected property name or '}'”; Safari “Property name must be a string literal”.

“Expected ',' or '}' after property value”

Two items have no comma between them, or a string contains an unescaped double quote that ends it early: "title": "The "best" pad thai" must be "The \"best\" pad thai".

“Bad control character in string literal”

A string contains a real line break or tab. Inside JSON strings they must be written as \n and \t. This often happens when JSON is built by joining strings instead of using JSON.stringify.

“Unexpected non-whitespace character after JSON”

A complete JSON value was followed by more text: two objects pasted together, an extra }, or JSON Lines (one object per line, used by many log tools). For JSON Lines, parse each line separately, or wrap the lines in [ ] with commas between them.

Python: “Expecting value: line 1 column 1 (char 0)”

Python's json.JSONDecodeError works the same way. Expecting value at char 0 means the text was empty or wasn't JSON at all (very often HTML). Print response.status_code and response.text[:200] before calling response.json(). Expecting property name enclosed in double quotes means single quotes or a trailing comma.

Quick reference

Chrome / Node.jsFirefoxSafariUsual cause
Unexpected end of JSON inputunexpected end of dataUnexpected EOFEmpty response, or cut-off JSON
Unexpected token '<'unexpected character at line 1 column 1Unrecognized token '<'HTML instead of JSON
Expected double-quoted property nameexpected property name or '}'Property name must be a string literalUnquoted key, single quotes, trailing comma
Expected ',' or '}' after property valueexpected ',' or '}' after property value in objectExpected '}'Missing comma, unescaped quote
Bad control character in string literalbad control character in string literalInvalid escape character / unterminated stringRaw line break or tab in a string
Unexpected non-whitespace character after JSONunexpected non-whitespace character after JSON dataUnexpected content at end of inputTwo values, or JSON Lines

For files that are mostly fine but sloppy, JSON Repair fixes the common mistakes in one go.

Frequently asked questions

Why does JSON.parse fail on valid-looking data?

Often because of something invisible: a byte-order mark at the start, curly quotes from a word processor, or a non-breaking space. Paste the text above to find the exact character.

How do I find where my JSON breaks?

Paste it above: the line and column are shown and the cursor jumps there. In code, the position number in the error is the character offset from the start.

Does JSON allow comments or trailing commas?

No. Standard JSON allows neither. Formats like JSONC (used by VS Code and tsconfig) and JSON5 do, but JSON.parse doesn't accept them.

Is my JSON uploaded?

No. Checking and explaining happen in your browser.

Updated