← Blog

JSON Formatting: 6 Common Mistakes and How to Fix Them

September 6, 2026 · 6 min read

Almost every modern API, config file, and data export speaks JSON. It looks friendly — a little like JavaScript — but it enforces rules far more strictly than most people expect. One misplaced comma, one stray single quote, or one missing brace is enough to make an entire document unreadable to a machine. This guide walks through the six mistakes that break JSON most often and shows exactly how to fix each one.

The good news is that none of these mistakes are hard to spot once you know what to look for. Most are habits carried over from writing JavaScript or config files, and each has a straightforward fix. A good formatter can even catch them for you automatically.

What valid JSON looks like

JSON, short for JavaScript Object Notation, is a plain-text format built from a handful of simple building blocks. Objects are wrapped in curly braces and hold key-value pairs separated by commas. Arrays are wrapped in square brackets and hold a comma-separated list of values. Strings sit inside double quotes, while numbers and booleans appear bare.

JSON supports six value types: objects, arrays, strings, numbers, booleans, and null. Numbers are written without quotes, as in 42 or 3.14, and booleans are the bare words true and false. There are no dates, comments, or functions in JSON — anything you want to represent must be expressed with those basic pieces.

A tiny valid document looks like this: {"name":"AITool.red","tools":16,"free":true}. The key name sits in double quotes, its value AITool.red also sits in double quotes, and the three pairs are separated by commas. An array of values might be [1, 2, 3], and a nested object such as {"settings":{"theme":"dark"}} is perfectly legal. If every character follows these rules, the document is valid; if even one does not, a parser rejects the whole thing with no partial credit.

Six common JSON mistakes

The errors below are responsible for most "invalid JSON" messages you will see. Each one is easy to make by habit — and usually just as easy to fix.

1. Trailing commas

A trailing comma sits after the last item in an object or array, right before the closing brace or bracket, as in {"name":"AITool.red",}. Many programming languages allow this as a convenience, so people carry the habit into JSON. JSON does not allow it, and a single stray comma makes the entire document fail.

How to fix it: delete the comma after the final item. Commas belong only between two items, never after the last one. A formatter that reports the exact error position will point straight at the offending comma.

2. Single quotes instead of double quotes

JavaScript code often wraps strings in single quotes, so it is natural to write {'name':'AITool.red'}. JSON accepts only double quotes around keys and string values, which means every single quote in a document is an error.

How to fix it: replace each single quote with a double quote. Watch out for apostrophes inside a value — if a string itself contains a double quote, escape it with a backslash as \".

3. Unquoted keys

A JavaScript object literal happily accepts {name:"AITool.red"}, with the key left bare. JSON requires every key to be a quoted string, so an unquoted key stops the parser immediately.

How to fix it: wrap the key in double quotes: {"name":"AITool.red"}. Do this for every key in every object, even short ones like id or url.

4. Comments

Adding // or /* ... */ notes to a config file feels helpful, because comments are a normal part of code. JSON has no comment syntax at all, so any comment makes the document invalid.

How to fix it: remove the comments. If you need to explain a value, store the explanation in a regular field such as "description", or keep your notes in a separate file that never gets parsed.

5. Missing or mismatched brackets and braces

Every { needs a matching }, and every [ needs a matching ], nested in the correct order. Forgetting a closer, or closing an object with a bracket, leaves the parser unable to find the end of the document.

How to fix it: check the pairs from the outside in, or paste the JSON into a formatter that highlights unbalanced brackets. Make sure each object closes with a brace and each array closes with a bracket.

6. Wrong top-level type

People sometimes assume a JSON document must begin with {. In fact the top level can be an object, an array, a string, a number, a boolean, or null. The genuine error is a top level that is none of those — for example, two objects sitting side by side with no container, or a bare word with no quotes.

How to fix it: make the whole document exactly one valid value. If you need several objects, wrap them in an array: [{"a":1},{"b":2}].

How to use the JSON Formatter

The quickest way to catch all six mistakes at once is to run your document through our JSON Formatter. It pretty-prints minified JSON into readable indented lines and, when something is wrong, tells you the line and character where parsing stopped.

A common real-world case is a minified API response that arrives on a single line. Formatting it first makes the nested structure visible, so you can confirm the fields you expect are present before you write any code against it.

  1. Paste or type your JSON into the input box.
  2. Click Format to pretty-print valid JSON, or Validate to check for errors.
  3. If the document is invalid, read the reported position and fix the mistake there.
  4. Click Format again, then copy the clean output.

Formatting is also a quick way to sanity-check structure: when the indentation suddenly looks lopsided, the odds are good that a brace or bracket is out of place.

FAQ

Why does my JSON keep failing to parse?

It is almost always a syntax error such as a trailing comma, single quotes, or an unquoted key. Paste the JSON into a formatter or validator to find the exact line and character where the parser gives up.

Is JSON the same as JavaScript?

No. JSON is a data format with stricter rules than JavaScript object literals. It requires double quotes around keys and strings, and it does not allow comments or trailing commas.

Can JSON have a number or a string at the top level?

Yes. The top level of valid JSON can be an object, an array, a string, a number, a boolean, or null — not only an object.

Prefer reading about other everyday formats? Head back to the AITool.red blog for more plain-English guides.