Few things slow development down like a JSON syntax error that suddenly breaks an API call, crashes a configuration load, or blocks a deployment. I have run into JSON errors while integrating third party APIs, editing config files by hand, and processing data streams. The good news is that most JSON errors follow predictable patterns. Once you recognize them, fixing them becomes routine instead of frustrating.
This guide walks through the most common JSON syntax errors I have personally encountered, explains why they happen, and shows how I resolved them in real development workflows. Everything here follows the official JSON specification defined in RFC 8259, which is the authoritative standard used by browsers, servers, and programming languages.
Table of Contents
- Understanding JSON Errors
- Error 1: Trailing Commas
- Error 2: Single Quotes
- Error 3: Unquoted Keys
- Error 4: Comments in JSON
- Error 5: Special Characters
- Error 6: Encoding Problems
- Error 7: Undefined and NaN Values
- Error 8: Bracket Mismatch
- Reliable Tools for Fixing JSON Errors
Understanding JSON Errors
JSON parsing is strict. When a parser encounters a character or structure that violates the specification, it stops immediately and throws an error. I usually see these errors while parsing API responses or reading configuration files during application startup.
try {
const data = JSON.parse(jsonString);
console.log(data);
} catch (error) {
console.error(error.message);
}
Most error messages point to what went wrong, but not always where the real mistake lives. Common hints include unexpected token messages, character positions, or line and column numbers.
Error 1: Trailing Commas
Trailing commas are the most common JSON error I encounter. This usually happens when JSON is written like JavaScript objects.
The Error
{
"name": "Alice",
"age": 25,
}
{
"colors": ["red", "green", "blue",]
}
The Fix
{
"name": "Alice",
"age": 25
}
{
"colors": ["red", "green", "blue"]
}
Why I Kept Hitting This
I work in JavaScript daily, where trailing commas are allowed. Switching contexts between JavaScript and JSON caused this mistake repeatedly until I started validating every JSON file.
Error 2: Single Quotes
JSON only allows double quotes. Single quotes will always cause a parse error.
The Error
{'name': 'Alice', 'age': 25}
The Fix
{"name": "Alice", "age": 25}
I ran into this frequently when copying data from JavaScript snippets or quick test objects.
Error 3: Unquoted Keys
All keys in JSON must be strings wrapped in double quotes. JavaScript allows unquoted keys, JSON does not.
The Error
{name: "Alice", age: 25}
The Fix
{"name": "Alice", "age": 25}
This error often appeared when configuration files were edited manually under time pressure.
Error 4: Comments in JSON
JSON does not support comments. Any comment syntax will break parsing.
The Error
{
"name": "Alice", // user name
"age": 25
}
The Fix
{
"name": "Alice",
"age": 25
}
When I needed documentation inside config files, I switched to description fields or used formats like JSONC only where explicitly supported.
Error 5: Special Characters
Certain characters must be escaped inside JSON strings. This error often showed up when handling file paths or user input.
The Error
{
"path": "C:\Users\Alice",
"message": "She said "Hello""
}
The Fix
{
"path": "C:\\Users\\Alice",
"message": "She said \"Hello\""
}
Using programmatic generation instead of manual string building eliminated most of these issues.
Error 6: Encoding Problems
JSON must be encoded as UTF 8. I encountered encoding errors when reading files created by external systems.
import json
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f)
Explicitly setting encoding prevented subtle bugs that were hard to diagnose.
Error 7: Undefined and NaN Values
JSON does not support undefined, NaN, or Infinity. This caused issues when serializing JavaScript objects directly.
The Error
{"value": undefined}
The Fix
{"value": null}
Relying on JSON.stringify helped normalize these values automatically.
Error 8: Bracket Mismatch
Missing or mismatched brackets usually appear in large or deeply nested JSON structures.
The Error
{
"items": [1, 2, 3
}
The Fix
{
"items": [1, 2, 3]
}
Counting brackets or using a validator quickly exposed these mistakes.
Reliable Tools for Fixing JSON Errors
After facing these issues repeatedly, I stopped debugging by eye alone. My first step is always validation using https://jsonformatterspro.com. It highlights the exact line and character where parsing fails and validates against the official JSON rules.
python -m json.tool data.json
jq . data.json
These tools caught errors faster than manual inspection, especially in large files.
Final Checklist I Use Before Shipping JSON
- All keys and strings use double quotes
- No trailing commas
- No comments present
- Special characters are escaped
- All brackets are properly closed
- No undefined, NaN, or Infinity values
- UTF 8 encoding without BOM
JSON errors are rarely complex. They are usually small, repeatable mistakes. With validation tools, trusted specifications, and consistent habits, debugging JSON becomes straightforward instead of stressful.