Common JSON syntax errors
Fix the mistakes that make a parser stop: trailing commas, single quotes, comments, and bare keys.
Short 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.
Related
Sources
- Introducing JSON — JSON.org