Skip to content
All guides

A little guidance

How to fix common JSON errors: trailing commas, quotes and comments

The mistakes that make JSON invalid most often, what JSON Prettifier says about each one, and how to fix them.

Advertisements

Fix JSON errors

Single quotes and a comment

We pasted JavaScript-style data with single quotes and a // comment. The check explained the first problem: JSON needs double quotes.

JSON with single-quoted keys and a comment; the bottom bar explains that property names need double quotes.
Each kind of mistake gets its own plain explanation. View full size
MistakeMessageFix
{'store': …}Property names need double quotes ("name"){"store": …}
// opening hoursComments aren’t allowed in JSONDelete the comment
[1, 2,]Remove the comma before ][1, 2]
undefinedundefined isn’t a JSON value. Use nullnull

JavaScript object syntax looks like JSON but is less strict.

Repeat this example

  1. Paste the data.
  2. Fix the problem named at the bottom.
  3. Repeat until it says Valid JSON.

Check the result

With double quotes and no comment, the check reads Valid JSON.

A common mistake

Replacing quotes inside text as well: only the quotes around keys and string values need to change.

Open JSON Prettifier

Sources and credits

Sample JSON made for these guides. The bookshop orders, names and emails are invented. Every screenshot shows the real tool working on that JSON.

Trailing commas

A comma after the last item, as in [1, 2,] or {"a": 1,}, is allowed in JavaScript but not in JSON. Remove the comma before ] or }.

Single quotes and unquoted keys

JSON needs double quotes around every key and string: {"name": "Ana"}, not {name: 'Ana'}. Replace single quotes with double quotes and quote every key.

Comments

JSON has no comments. Delete // and /* */ comments, or move the note into a value such as "note": "…".

JavaScript values

undefined, NaN, Infinity and functions don’t exist in JSON, and True, False and None are Python, not JSON. Use null, true and false in lowercase.

  • JSON Prettifier

    How to check if JSON is valid and find the error

    JSON Prettifier checks JSON as you type and names the exact line and column of the first error, with a plain explanation and Go to error.

Advertisements