Skip to content

TechnologyPublished About 1 min read

Linked sources: JSON.org. See source links. Date is the page publish date, not a byline.

Common JSON syntax errors

Fix the mistakes that make a parser stop: trailing commas, single quotes, comments, and bare keys.

The answer

If a parser rejects the text, look first for a trailing comma, a single-quoted string, a comment, or a key that is not in double quotes.

A short checklist

Trailing commas are legal in many programming languages and illegal in JSON. Comments with // or /* are illegal. NaN and Infinity are not JSON numbers. A leading zero on a number, such as 01, is illegal. Undefined is not null; use null when you mean an empty value.

Escape a double quote inside a string with a backslash. A raw line break inside a string is illegal; use \n. After you change something, format it again. A second failure means there was a second problem, which is common in a large paste.

Common mistakes

  • ×

    Rewriting the whole file when the failure is one comma.

  • ×

    Running the text as code to “see if it works.”

Frequently asked questions

Why not auto-repair?

A repair can change the data. It is better to see the failure and edit the source.

Sources

Linked publisher pages. Opening a link is not the same as this site verifying the article body.

What do you want to do next?