EsyTool
Developer Tools

Why Your JSON Won't Parse: Common Syntax Errors Explained

"Unexpected token" is the least helpful error message in software. Here are the actual syntax mistakes that break JSON, and how to spot them fast.

June 30, 20265 min read
Validate and format your JSON instantly

"Unexpected token in JSON at position 47" is one of the most common errors in web development and one of the least useful — it tells you where the parser gave up, not what's actually wrong. Most JSON syntax errors fall into a small set of repeat offenders.

Trailing commas

JavaScript object literals tolerate a trailing comma after the last item; strict JSON does not. This is the single most common JSON error for people coming from JavaScript.

{
  "name": "Alex",
  "age": 30,
}

The comma after 30 is invalid — remove it and the object parses fine.

Single quotes instead of double quotes

JSON requires double quotes for both keys and string values. Single quotes are valid in JavaScript object literals but not in JSON — this trips people up constantly when copy-pasting from JS code into a JSON file or API payload.

{ 'name': 'Alex' }  // invalid JSON
{ "name": "Alex" } // valid

Unquoted keys

Again, valid in JS object literals, invalid in JSON — every key must be a double-quoted string.

{ name: "Alex" }     // invalid
{ "name": "Alex" }  // valid

Comments

JSON has no comment syntax at all — no //, no /* */. If you're editing a hand-written config file and add a comment for your future self, standard JSON.parse will reject the entire file. (Some tools support a relaxed superset like JSON5 or JSONC that does allow comments — but that's not JSON, and a strict parser will still choke on it.)

Mismatched or missing brackets/braces

An extra or missing } or ] is easy to introduce when manually editing nested structures, and the resulting error position often points nowhere near the actual mistake — the parser just fails once it runs out of matching closers. This is the case where a formatter that visually indents your JSON is far more useful than reading the raw error message, since a missing brace becomes obvious once the nesting is displayed properly.

NaN, undefined, and Infinity

These are valid JavaScript values but have no representation in JSON. If an API accidentally serializes a NaN (a common bug when a calculation divides by zero somewhere upstream), the resulting JSON is invalid and every consumer of it will fail to parse.

The fastest way to actually find the problem

Rather than scanning by eye, paste the JSON into a validator that both formats it (revealing structural issues like bracket mismatches through indentation) and points to the specific line and character of the syntax error. For large API responses or config files, this turns a multi-minute manual scan into a few seconds.

Try JSON Formatter & Validator now

Free, runs entirely in your browser — no upload, no sign-up.

Open JSON Formatter & Validator