Developers ·

Five common JSON errors and how to read them

JSON is strict. A single stray comma makes a whole document invalid, and browser error messages do not always point at the real cause. These are the five mistakes behind most of them.

1. Trailing commas

JavaScript allows a comma after the last item in an array or object. JSON does not. The parser reaches the closing bracket while expecting another value.

[1, 2, 3,]      invalid
[1, 2, 3]       valid

2. Single quotes

Strings and keys must use double quotes. Single quotes are a common habit from JavaScript and Python, and the parser stops at the first one.

{'name': 'Ada'}     invalid
{"name": "Ada"}     valid

3. Unquoted keys

Every key needs double quotes, even when it is a simple word. An error such as “expected property name” usually means this.

{name: "Ada"}       invalid
{"name": "Ada"}     valid

4. Comments

JSON has no comment syntax. Configuration files that allow // or /* */ comments are using JSONC or JSON5, which standard parsers reject. Remove the comments, or store notes in a field such as "_comment".

5. Values JSON does not have

undefined, NaN, Infinity, functions and dates are not JSON values. Use null for missing values, and strings for dates, ideally in ISO 8601 format such as "2026-10-02T09:30:00Z".

Reading the error location

Parsers report where they gave up, which is often just after the real mistake. If the error points at a closing bracket, look at the line before it for a trailing comma. If it points at the very end, a bracket or quote was never closed. The JSON formatter shows the line and column so you can jump straight to it.

Frequently asked questions

Are newlines allowed inside JSON strings?

Not as raw line breaks. Write them as \n inside the string.

Does key order matter?

Not to the JSON standard, which treats objects as unordered. Most parsers preserve the order you wrote, though.

Advertisement

Related articles