5 Common JSON Mistakes That Break Your Code (And How to Fix Them Instantly)
Published: July 6, 2025 · 6 min read
JSON looks deceptively simple. It's just text, right? Keys and values wrapped in braces. Yet almost every developer has stared at a cryptic "Unexpected token" error, convinced their JSON is perfectly valid, only to discover — minutes later — a single misplaced comma was the culprit.
The problem is that JSON's syntax rules are stricter than they appear. Unlike JavaScript object literals (which are forgiving), the JSON spec is merciless. One small mistake and your entire payload fails to parse. Let's walk through the five most common JSON errors, why they happen, and how to fix them fast.
Mistake #1: Trailing Commas
This is the single most common JSON error — and the hardest to spot by eye. In JavaScript objects, trailing commas are perfectly legal. In JSON, they are a syntax error.
❌ Wrong:
{
"name": "Alice",
"email": "alice@example.com",
"role": "admin", <-- Trailing comma kills your JSON
}
✅ Correct:
{
"name": "Alice",
"email": "alice@example.com",
"role": "admin" <-- No comma after the last property
}
Why it happens: Developers writing JSON by hand naturally apply JavaScript habits. If you're copying data out of a JS file or editing config manually, trailing commas creep in. They also sneak into arrays: ["a", "b", "c",] is invalid JSON.
Quick fix: Paste your JSON into a JSON Formatter/Validator — it will highlight the exact line and column of any trailing comma, saving you the eye-strain.
Mistake #2: Single Quotes Instead of Double Quotes
JavaScript accepts both single and double quotes for strings. JSON only accepts double quotes. Period.
❌ Wrong:
{
'title': 'Hello World',
'message': 'This will fail to parse'
}
✅ Correct:
{
"title": "Hello World",
"message": "This parses correctly"
}
Why it happens: Python developers are especially prone to this — Python happily uses single quotes for dict keys. Hand-writing JSON in a text editor without proper syntax highlighting also masks the issue.
Quick fix: Use an editor with JSON-aware syntax highlighting (VS Code, Sublime Text). Single-quoted keys and values will typically show in the wrong color, immediately flagging the problem.
Mistake #3: Unquoted Keys
In JavaScript, object keys don't need quotes if they're valid identifiers. JSON requires all keys to be double-quoted strings, no exceptions.
❌ Wrong:
{
name: "Bob",
age: 30,
isActive: true
}
✅ Correct:
{
"name": "Bob",
"age": 30,
"isActive": true
}
Why it happens: This is another JavaScript-object-literal muscle-memory issue. Developers quickly jot down data structures without quotes, forgetting that JSON parsers are not JavaScript engines.
Mistake #4: Comments in JSON
JSON does not support comments. Not // single-line, not /* block */. Nothing. The JSON specification intentionally omits comments to keep the format purely for data interchange.
❌ Wrong:
{
// User configuration
"username": "carol", /* main account */
"theme": "dark" // preferred theme
}
✅ Correct:
{
"username": "carol",
"theme": "dark"
}
Why it happens: Developers use JSON files for configuration (package.json, tsconfig.json, .prettierrc), and configuration begs for comments. The frustration is so widespread that some tools — like VS Code's settings.json and TypeScript's tsconfig.json — actually do support comments via JSON-with-comments (JSONC). But standard JSON parsers will choke.
Workaround: If you absolutely need inline documentation, use a "_comment" key as a convention — but know that it becomes part of your data and may trip up validators expecting specific schemas.
Mistake #5: Missing or Mismatched Brackets
JSON structures nest — objects inside arrays inside objects. It's easy to lose track of which brace closes what, especially in deeply nested API responses or configuration files.
❌ Wrong:
{
"users": [
{
"id": 1,
"name": "Dan"
}, <-- Array closes here, but...
], <-- ...object should close here
}
At first glance, the brackets might look balanced. But a missing } or ] buried 50 lines deep is a nightmare to hunt down manually.
Quick fix: This is where a tool like our JSON Formatter becomes invaluable. Paste your malformed JSON, and it shows you the exact line where the structure breaks — complete with line numbers. It also pretty-prints the JSON with indentation that makes bracket pairing visually obvious.
How to Avoid JSON Errors Before They Happen
- Use a linter in your editor. VS Code's built-in JSON validation catches most errors as you type. Install the Prettier extension and set it to format on save.
- Never hand-write production JSON. Always generate JSON programmatically using
JSON.stringify()in JavaScript,json.dumps()in Python, or your language's equivalent serializer. - Validate before you deploy. Before committing JSON configuration changes or sending an API payload, paste it into the ZaiXian Tools JSON Formatter. It validates, pretty-prints, and shows errors with line numbers — all in your browser, no data sent to any server.
- Watch your copy-paste. Copying JSON from a web page, a log file, or a chat message can introduce invisible characters (smart quotes, zero-width spaces) that break parsing. Re-type suspect sections or run through a validator.
JSON errors are frustrating precisely because they're so small. A single character — one comma, one quote mark — is all it takes to bring down an entire application. But with the right habits and a good validator bookmarked, you can catch these mistakes in seconds instead of spending an hour squinting at brackets. Keep our JSON Formatter handy →