Utilora

How to find and fix a JSON error

What a JSON parse error is really telling you, the four mistakes that cause almost all of them, and how to locate the position quickly.

2 min read

JSON has no comments, no trailing commas and no unquoted keys. The format is strict on purpose: a machine has to read it without guessing. When a parser fails, it stops at the first thing it cannot read and reports the position it reached.

What the error is telling you

Two things: what it expected, and where it stopped. The position is usually just after the real mistake, not on it. That is why the fix is so often one line above the line named in the message.

The four mistakes behind almost every JSON error

A trailing comma

{
  "tools": 25,
}

The comma after 25 has nothing to follow it. Remove it.

Single quotes, or keys without quotes

{ 'name': utilora }

JSON strings need double quotes, and keys have to be strings as well: {"name": "utilora"}.

Comments

{
  // how many tools
  "tools": 25
}

Comments belong to JavaScript and JSON5, not to JSON. Delete them, or move the note into a real field such as "note": "...".

Unbalanced brackets or braces

Nested objects are where this happens. One missing } can make the parser complain about a line far below the actual problem.

How to find it quickly

  1. Paste the text into JSON Formatter and press Validate. The message names the problem and the position your browser's parser reached.
  2. If the file is long, format it first — indentation makes a missing bracket visible at a glance.
  3. Fix one thing at a time and validate again. A single missing brace can produce a dozen errors, and chasing them all at once is wasted effort.
  4. Keep a copy of the original before you start editing.

When the JSON looks fine but still fails

Sometimes the text is not JSON yet. A payload pasted out of a log, an email or a URL may be encoded, and the parser is failing on the wrapper rather than the data. Base64 Encoder and Decoder and URL Encoder and Decoder turn those back into text you can read and check.

Validating is not the same as formatting

Validation answers one question: will a machine read this? Formatting makes it readable by people. Both are worth doing before you commit a config file, and neither should change your data — a formatter that silently "fixed" invalid JSON would be worse than the error it hid.

Tools used here: JSON Formatter · Base64 Encoder and Decoder · URL Encoder and Decoder

Frequently asked questions

Why does the error point at a line that looks fine?

A parser reports where it stopped, not where the mistake began. A missing brace often makes it complain about a line much further down the file.

Can a tool repair invalid JSON automatically?

It can guess, but a guess that changes your data is worse than an error. Fixing the syntax yourself keeps the data exactly as it was.