Common JSON Errors and How to Fix Them
Every JSON developer hits these at some point. Here’s a reference for the errors that come up most often, with invalid and corrected examples.
Tip: paste your JSON into the JSON Validator to get the exact line and column of the error.
1. Missing Comma Between Elements
Every key-value pair in an object (and every item in an array) must be separated by a comma, except the last one.
{
"name": "Alice"
"age": 30
}{
"name": "Alice",
"age": 30
}2. Trailing Comma After Last Element
JSON does not allow a comma after the last item in an object or array. This differs from JavaScript and JSON5.
{
"name": "Alice",
"age": 30,
}{
"name": "Alice",
"age": 30
}3. Single Quotes Instead of Double Quotes
JSON requires double quotes for both keys and string values. Single quotes are valid in JavaScript but not in JSON.
{'name': 'Alice'}{"name": "Alice"}4. Unquoted Keys
Unlike JavaScript object literals, JSON requires all keys to be wrapped in double quotes.
{name: "Alice"}{"name": "Alice"}5. Comments
Standard JSON does not support comments (// or /* */). Use JSON5 or strip comments before parsing.
{
// This is a comment
"name": "Alice"
}{
"name": "Alice"
}6. undefined, NaN, Infinity
undefined, NaN, and Infinity are JavaScript values but not valid JSON. Use null, or convert numbers before serializing.
{"value": undefined, "ratio": NaN}{"value": null, "ratio": null}7. Unmatched Braces or Brackets
Every opening brace { must have a matching }, and every opening bracket [ must have a matching ]. Mixed delimiters always fail.
{"items": [1, 2, 3}{"items": [1, 2, 3]}8. Strings with Unescaped Special Characters
Backslashes in strings must be escaped as \\. Similarly, double quotes inside strings must be escaped as \".
{"path": "C:\Users\name"}{"path": "C:\\Users\\name"}Quick Diagnostic Checklist
- Are all string values and keys wrapped in double quotes?
- Is there a comma after every element except the last?
- Do all braces and brackets match and nest correctly?
- Are there any // or /* */ comments?
- Are there any JavaScript-only values (undefined, NaN, Infinity)?
- Are backslashes and double quotes escaped inside strings?
Related guides: JSON Syntax · What is JSON? · JSON Data Types