Common JSON Mistakes and How to Avoid Them
Even experienced developers make mistakes when writing JSON by hand. A single misplaced comma or missing quote can break an entire API integration. In this comprehensive guide, we cover the 12 most common JSON mistakes, show examples of each, explain why they happen, and demonstrate how to fix and prevent them using our JSON Validator and JSON Repair tools.
1. Trailing Commas
The problem: Adding a comma after the last element in an object or array.
// Invalid — trailing comma after "age"
{
"name": "Alice",
"age": 30,
}
// Invalid — trailing comma after 3
[1, 2, 3,]
Why it happens: JavaScript, Python, and many other languages allow trailing commas, so developers carry that habit into JSON. But JSON strictly forbids them.
How to fix: Our JSON Repair tool automatically detects and removes trailing commas. You can also run your JSON through our JSON Linter which flags trailing commas as errors.
2. Unquoted Object Keys
The problem: Omitting quotes around object keys.
// Invalid
{name: "Alice", age: 30}
// Valid
{"name": "Alice", "age": 30}
Why it happens: JavaScript object literals allow unquoted keys, so developers assume JSON works the same way. It does not.
How to fix: Always wrap keys in double quotes. Use our JSON Formatter which automatically corrects unquoted keys when formatting.
3. Using Single Quotes
The problem: Using 'single quotes' instead of "double quotes" for strings.
// Invalid
{'name': 'Alice'}
// Valid
{"name": "Alice"}
Why it happens: Many programming languages accept single and double quotes interchangeably. JSON is strict: only double quotes are valid.
How to fix: Our JSON Fixer converts single quotes to double quotes throughout your JSON document.
4. Comments in JSON
The problem: Adding // or /* */ comments in standard JSON.
// Invalid
{
"name": "Alice", // user's name
"age": 30 /* in years */
}
Why it happens: Developers want to document their JSON, but JSON has no comment syntax.
How to fix: Use JSONC (JSON with Comments) if your tools support it, or add metadata fields like "_comment": "user's name". Our JSONC to JSON converter strips comments for production use.
5. Missing or Extra Commas
The problem: Missing a comma between items or adding an extra comma (not trailing, but between items).
// Missing comma
{"a": 1 "b": 2}
// Extra comma
[1,,2]
How to fix: Our JSON Validator pinpoints the exact location of missing or extra commas with clear error messages.
6. Incorrect Number Formatting
The problem: Using leading zeros, octal numbers, hexadecimal, or special float values.
// Invalid
{"value": 01} // leading zero
{"value": 0xFF} // hex not allowed
{"value": NaN} // NaN not allowed
{"value": Infinity} // Infinity not allowed
// Valid
{"value": 1}
{"value": 255}
{"value": null}
Why it happens: Different programming languages have different number literal rules. JSON uses decimal notation only.
7. Mismatched Brackets
The problem: Missing opening or closing braces/brackets.
// Missing closing brace
{"name": "Alice", "items": [1, 2, 3}
Why it happens: Deeply nested JSON makes it easy to lose track of bracket pairs.
How to fix: Use our JSON Depth Analyzer to visualize nesting structure, and JSON Linter to catch mismatches.
8. Duplicate Keys
The problem: Using the same key name twice in one object.
{"name": "Alice", "name": "Bob"}
Why it matters: While technically valid (the last value wins), duplicate keys almost always indicate a bug. They can come from merging objects or copy-paste errors.
How to fix: Our JSON Duplicate Key Detector flags all duplicate keys. Our JSON Merge tool handles conflicts explicitly.
9. Incorrect Boolean Values
The problem: Using True, False, TRUE, FALSE, yes, or no instead of lowercase true and false.
// Invalid
{"active": True, "verified": yes}
// Valid
{"active": true, "verified": true}
Why it happens: Python uses True/False, YAML uses yes/no, leading to confusion.
10. Using undefined Instead of null
The problem: JavaScript developers sometimes use undefined in JSON, which is not valid.
// Invalid
{"middleName": undefined}
// Valid
{"middleName": null}
11. Encoding Issues
The problem: Non-UTF-8 encoding or BOM (Byte Order Mark) at the start of JSON files.
Why it happens: Some Windows tools add a BOM character that JSON parsers don't expect.
How to fix: Always save JSON files as UTF-8 without BOM. Our JSON Validator detects encoding issues.
12. Extremely Deep Nesting
The problem: Nesting objects more than 10-15 levels deep.
Why it matters: Deep nesting makes JSON hard to read, parse, and debug. Some parsers have depth limits.
How to fix: Use our Nested to Flat JSON converter to flatten deeply nested structures into dot-notation key-value pairs.
How to Catch All These Mistakes Automatically
Instead of debugging manually, build a JSON validation pipeline:
- Step 1: Run your JSON through JSON Validator for syntax checking
- Step 2: Use JSON Linter for style and convention checks
- Step 3: Run Duplicate Key Detector for structural issues
- Step 4: Use JSON Repair to fix any remaining issues
- Step 5: Validate against a schema with JSON Schema Validator
All these tools work entirely in your browser. No data ever leaves your machine.