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
- Format the content so the structure is visible.
- Validate it and jump to the reported line.
- Check the comma or quotes around that point.
- Minify only after the JSON is valid.