Developer Tools

The Most Common JSON Errors – and How to Fix Each One

“Unexpected token” tells you something is wrong, not what. These are the mistakes behind almost every JSON error, with quick fixes.

In this article
  1. Why JSON is so strict
  2. The usual suspects
  3. Reading the error position
  4. Duplicate keys: the silent bug
  5. Copy-paste traps
  6. How to validate
  7. Config files that allow comments
  8. Private checking

Why JSON is so strict

JSON looks like JavaScript, but its rules are much stricter so that every program in every language reads it the same way. Things JavaScript tolerates – trailing commas, single quotes, comments – are errors in JSON. The JSON Validator checks against the official standard (RFC 8259) and points to the line and column of the problem.

JSON ValidatorCheck whether JSON is valid against the RFC 8259 standard. Get the exact line and column of each error, duplicate-key warnings and a structure summary.
Open the free tool

The usual suspects

MistakeBrokenFixed
Trailing comma{"a": 1, "b": 2,}{"a": 1, "b": 2}
Single quotes{'name': 'Ali'}{"name": "Ali"}
Unquoted key{name: "Ali"}{"name": "Ali"}
Comment{"a": 1 // note}Remove the comment
Missing comma{"a": 1 "b": 2}{"a": 1, "b": 2}
Unescaped quote in text{"q": "He said "hi""}{"q": "He said \"hi\""}
Special values{"x": NaN, "y": undefined}Use null or a number
Leading zero{"code": 007}{"code": "007"} (as text)

Reading the error position

The error is usually at or just before the position reported. If the validator says “line 14, column 3”, look at the end of line 13 too – a missing comma there only becomes a problem when the next line starts. For a missing closing bracket, the error may appear at the very end of the file; count your opening and closing brackets in the formatted version.

Duplicate keys: the silent bug

JSON like {"price": 10, "price": 12} is accepted by many parsers, which quietly keep the last value. That can cause bugs that are very hard to track down – a config setting that “does not work” because it is overridden further down. The validator warns about duplicate keys that other tools ignore.

Copy-paste traps

  • Curly quotes: word processors and chat apps change " into “ and ”. JSON only accepts straight quotes.
  • Invisible characters: non-breaking spaces and byte-order marks from documents. Clean them with Remove Extra Spaces.
  • Half a response: logs and consoles sometimes cut long output. If the error is “unexpected end”, check that you copied everything.

How to validate

  1. Paste your JSON into the JSON Validator.
  2. Read the result: valid, or an error with line and column.
  3. Fix and re-check. For valid JSON, the summary shows type, number of keys, nesting depth and size.
  4. Format it neatly with the JSON Formatter.

Config files that allow comments

Some tools use JSON-like formats that do allow comments or trailing commas – such as VS Code settings (JSONC) or JSON5. Those files are not strict JSON, so a strict validator will complain. If a tool’s documentation says comments are allowed, trust that tool; if the file is sent to an API, use strict JSON.

Private checking

Configuration files often contain passwords and keys. Validation happens in your browser, and nothing is uploaded.

JSON ValidatorCheck whether JSON is valid against the RFC 8259 standard. Get the exact line and column of each error, duplicate-key warnings and a structure summary.
Open the free tool
Keep reading

Related articles

All articles
Dev

How to Read JSON – A Beginner’s Guide to API Responses

Almost every app and website exchanges data as JSON. Once you can read its structure, error messages and API responses stop looking like noise.

3 min read
Dev

Should You Minify JSON? Size, Speed and How Gzip Changes the Picture

Minifying JSON removes spaces and line breaks. It sounds like an obvious win – but how much does it really save, and when should you not bother?

3 min read
Dev

How to Read Messy Links Full of % Codes

Links copied from emails, search results and ads are often a jumble of percent codes. Decoding them shows what they really say – and where they really go.

3 min read