🌐 English

Home › Guides

10 common JSON errors and how to fix them

JSON has few rules, but those rules are strict, so one small slip makes the whole document unreadable. Error messages usually give a position but not a reason. Knowing the ten usual suspects lets you fix most problems in seconds.

Commas and brackets

The most frequent slip is a trailing comma. {"a":1,"b":2,} looks natural to a human eye but is invalid JSON. The opposite also happens: a missing comma between items, as in {"a":1 "b":2}.

Second come mismatched brackets. In deeply nested data it is hard to see whether a brace { } or a square bracket [ ] was left open. Letting a tool re-indent the text shows immediately where the structure goes wrong.

Quotes and escapes

Strings and keys in JSON must use double quotes. Single quotes as in {'a':1}, or an unquoted key as in {a:1}, are errors. This often appears when values are copied from another settings format.

Inside a string, double quotes, backslashes and line breaks cannot be typed directly; they must be escaped as \", \\ and \n. A Windows path like C:\temp pasted raw either fails or turns \t into a tab.

Errors in value types

JSON accepts only strings, numbers, true, false, null, arrays and objects. Spellings like True, None, undefined or NaN are not valid, and the keywords must be lowercase.

Numbers have rules too. Leading zeros as in 007, forms like .5 or +1, and hexadecimal such as 0xFF are not allowed. There is no date type, so dates must be written as strings.

Comments and invisible characters

JSON has no comments. Adding // or /* */ causes an error. If you need explanations, add a separate field or choose a format that allows comments.

Invisible characters cause trouble too: a byte order mark at the start of a file, odd spaces created by copying, and curly quotes inserted by word processors. A curly quote “ ” is a different character from the straight quote ".

Finding the problem quickly

The position in an error message (line and column) is where the parser noticed the problem, which can differ from where the cause lies. If a comma is missing, the error is reported at the next item. Always look at the part just before the reported spot too.

For large data, halving works well: check one half at a time, and the formatted view stays clean until the point where it breaks. The JSON formatter on this site tidies input and shows where an error sits.