Ctrl K

Common JSON Errors and How to Fix Them

intermediate TheToolSera Team 8 min read Updated 18 Apr 2026

JSON parsers fail loudly and with very little sympathy. The good news is that almost every error comes from one of a dozen causes. This guide maps the message you see to the thing that is actually wrong.

How to read a parse error

Most parsers report a character offset or a line and column. That location is where the parser gave up, not necessarily where the mistake is: a missing closing brace is usually reported at the end of the file. Always look upward from the reported position.

Unexpected token < in JSON at position 0

This is the most reported JSON error and it is almost never a JSON problem. A request expected JSON but received HTML — typically a 404 page, a login redirect, a proxy error page or a framework stack trace. Open the network tab, look at the raw response body and the status code, and fix the request or the endpoint.

Check the Content-Type response header. If it says text/html, the server never intended to send JSON.

Trailing commas

Invalid
{
  "a": 1,
  "b": 2,
}
Valid
{
  "a": 1,
  "b": 2
}

JavaScript, TypeScript and Python all tolerate trailing commas, so they slip in constantly when JSON is hand-edited. JSON does not allow them anywhere.

Quote problems

  • Single quotes: 'value' must be "value"
  • Smart quotes: “value” from a word processor or chat app looks identical but is a different character
  • Unquoted keys: { key: 1 } must be { "key": 1 }
  • Unterminated string: a missing closing quote makes the parser swallow the rest of the file

Curly/smart quotes are the hardest to spot because they render almost identically. If a line looks correct but still fails, retype the quotes by hand.

Escaping mistakes

Backslashes and quotes inside strings must be escaped
{
  "path": "C:\\Users\\ada\\data.json",
  "quote": "She said \"hello\"",
  "newline": "line one\nline two"
}

A literal newline or tab inside a string is invalid — control characters must be escaped as \n, \t, \r and so on. This trips people up when a multi-line value is pasted directly into a string.

Encoding and invisible characters

  • A UTF-8 byte-order mark (BOM) at the start of a file makes strict parsers fail at position 0 — save the file as UTF-8 without BOM
  • Non-breaking spaces copied from web pages are not valid whitespace in JSON
  • Files saved as UTF-16 will not parse as JSON; convert to UTF-8

Structural mistakes

Unbalanced braces or brackets

Format the document: a formatter reports the exact point where nesting breaks, and correct nesting becomes visible after indentation.

Two documents in one file

{...}{...} is not valid. Wrap the objects in an array, or emit one object per line as NDJSON and parse line by line.

Duplicate keys

Technically permitted by the spec, but parsers keep only one value — usually the last. Deduplicate before it causes a silent data loss bug.

undefined, NaN or Infinity

These come from JavaScript and Python serialisers. Replace with null, or a sentinel value your consumer understands.

A repeatable debugging routine

Find and fix an invalid JSON document

  1. 1

    Confirm it is really JSON

    Check the first characters. A leading < means HTML, a leading BOM means an encoding issue.

  2. 2

    Run a validator

    Get the exact line and column of the first failure rather than guessing.

  3. 3

    Look upward from the error

    Missing closing tokens are always reported later than the real mistake.

  4. 4

    Format the document

    Indentation makes unbalanced nesting obvious at a glance.

  5. 5

    Re-validate

    Repeat until clean — one syntax error commonly masks another.

  6. 6

    Add validation upstream

    If the file is machine-generated, fix the producer so the same class of error cannot return.

JSON Validator

Get line-and-column error reporting on your document, entirely in the browser.

Try JSON Validator

Frequently asked questions

What does "Unexpected end of JSON input" mean?

The document ended while the parser was still expecting something — usually a missing closing brace or bracket, or a truncated response body.

Are duplicate keys allowed in JSON?

The specification permits them but leaves behaviour undefined. Most parsers keep the last occurrence, so treat duplicates as a bug.

Can comments be added to JSON?

No. Use a "_comment" field, or a superset like JSONC or YAML if your tooling supports it.

Why does my JSON work in JavaScript but fail in a validator?

You are almost certainly using a JavaScript object literal — unquoted keys, single quotes or trailing commas — rather than JSON.

Put this into practice

JSON Validator runs entirely in your browser — no upload, no account, no limits.

Open JSON Validator

Related tools

Related guides

All guides

Explore related topics