Data & development

Common JSON errors and how to fix them

JSON is strict: use double quotes, avoid trailing commas and comments, and put every object key in quotes.

A JSON object can look right and still fail to load a configuration or an API response. The quickest way to find the problem is to validate the complete document and read the reported line and column, but recognizing common patterns lets you fix many errors immediately.

1. Trailing commas

JSON does not allow a comma after the final item in an object or array. This is valid:

{"name": "Ana", "active": true}

A comma after true is not standard JSON. Some programming languages allow trailing commas in their own objects, but JSON.parse() does not.

2. Single quotes

Keys and strings must use double quotes. Change {'name': 'Ana'} to {"name": "Ana"}. Single quotes can appear inside a value, but they cannot delimit a JSON string.

3. Unquoted keys

JavaScript can accept {name: "Ana"} in some contexts. JSON cannot: every object key must be wrapped in double quotes, as in {"name": "Ana"}.

4. Comments and invalid values

Standard JSON does not allow // or /* ... */ comments. It also does not accept undefined, NaN or Infinity. Use null when you need to represent a missing value and check that numbers use JSON syntax.

A quick debugging routine

  1. Format the content so the structure is visible.
  2. Validate it and jump to the reported line.
  3. Check the comma or quotes around that point.
  4. Minify only after the JSON is valid.