10+ Common JSON Errors and How to Fix Them
Published: May 25, 2025 ยท Last updated: June 20, 2025 ยท 11 min read
Every developer has seen the dreaded "Unexpected token" or "JSON.parse error" message. JSON has strict syntax rules, and even a tiny mistake breaks the entire document. This comprehensive guide covers all the common errors, debugging strategies, and tools to help you fix JSON issues quickly.
Error 1: Trailing Commas
The most common JSON error. JavaScript allows trailing commas, but JSON does not. This trips up developers constantly because they're used to JavaScript's more lenient syntax.
Invalid:
Fixed:
Rule: The last item in an object or array must NOT have a comma after it. This applies to both arrays and objects at every nesting level.
Error 2: Single Quotes Instead of Double Quotes
JSON requires double quotes for all strings and keys. Single quotes are completely invalid, even though many programming languages allow them for strings.
Invalid:
Fixed:
Rule: Always use double quotes (") for both keys and string values. Never single quotes (') or backticks.
Error 3: Unquoted Keys
In JavaScript objects, keys don't need quotes unless they contain special characters. In JSON, all keys must be double-quoted strings โ no exceptions.
Invalid:
Fixed:
Rule: Every key in JSON must be a double-quoted string, even if it's a simple identifier.
Error 4: Missing Commas Between Properties
Forgetting a comma between key-value pairs is easy to do, especially when editing multi-line JSON manually or when copy-pasting sections.
Invalid:
Fixed:
Rule: Every key-value pair must be followed by a comma, except the last one. Same applies to array elements.
Error 5: Unmatched Brackets or Braces
Opening a bracket or brace without closing it โ or closing one that was never opened. This is especially common in deeply nested structures.
Invalid:
Fixed:
Rule: Every { needs a matching }, and every [ needs a matching ]. Use an editor with bracket matching and highlighting to catch these errors quickly.
Error 6: Invalid Escape Sequences
JSON strings support a limited set of escape sequences. Using unsupported escapes or forgetting to escape special characters causes parsing failures.
Invalid:
Fixed:
Valid escape sequences in JSON:
\"โ double quote\\โ backslash\/โ forward slash (optional)\bโ backspace\fโ form feed\nโ newline\rโ carriage return\tโ tab\uXXXXโ Unicode character (4 hex digits)
Error 7: NaN and Infinity Values
JavaScript's special numeric values NaN, Infinity, and -Infinity are not valid in JSON. They must be represented differently.
Invalid (will fail to parse):
Options for fixing:
Note: When using JSON.stringify() in JavaScript, NaN and Infinity are automatically converted to null.
Error 8: Comments in JSON
Standard JSON does not support comments. This surprises many developers who want to document their configuration files.
Invalid:
Workarounds:
Error 9: Duplicate Keys
While technically valid JSON (parsers accept it), duplicate keys cause unpredictable behavior. Different parsers handle duplicates differently โ some keep the first value, others keep the last.
Problematic:
Best practice: Ensure all keys within an object are unique. Our JSON Formatter can detect and warn about duplicate keys.
Error 10: Incorrect Boolean and Null Casing
JSON boolean and null values must be lowercase. Other casings are treated as invalid or as string values.
Invalid:
Fixed:
Rule: Always use lowercase true, false, and null. Python developers: note that Python uses True, False, and None โ but JSON requires lowercase.
Error 11: Unicode and Encoding Issues
JSON must be encoded in UTF-8 (per RFC 8259). Character encoding mismatches cause parsing failures or garbled text.
Common symptoms:
- Replacement characters appearing:
{"name": "Caf๏ฟฝ"} - Unexpected characters:
{"name": "Cafรยฉ"} - Parse errors on seemingly valid JSON
Solutions:
- Ensure source files are saved as UTF-8 (without BOM)
- Set proper Content-Type header:
application/json; charset=utf-8 - Use Unicode escape sequences for problematic characters:
{"name": "Caf\u00e9"} - Verify database and API connections use UTF-8
Error 12: Numeric Precision Issues
JSON numbers are parsed as IEEE 754 double-precision floating-point numbers in most languages. This causes precision loss for very large integers or precise decimals.
Problem โ large ID loses precision:
Solution โ use strings for large numbers:
Safe integer range: Numbers between -(2^53 - 1) and (2^53 - 1) are safe. That's approximately ยฑ9 quadrillion. Beyond that, use strings.
Debugging Strategies: A Systematic Approach
When facing a JSON parsing error, follow this systematic debugging process:
Step 1: Locate the Error Position
Most JSON parsers report the line number and character position where parsing failed. The actual error is usually slightly before this position โ often the previous line or a few characters back.
Step 2: Isolate the Problem
For large JSON documents, use binary search to isolate the problematic section:
- Copy the first half of the JSON and try parsing it
- If it parses, the error is in the second half
- If it fails, the error is in the first half
- Repeat until you find the specific line
Step 3: Check Common Culprits
At the error location, check for these issues in order:
- Missing or extra comma on the previous line
- Unescaped quotes or backslashes in strings
- Single quotes instead of double quotes
- Unquoted key names
- Missing closing bracket or brace
- Trailing comma before a closing bracket/brace
Step 4: Use a Validator Tool
Paste your JSON into a validation tool that highlights the exact error location. Our JSON Formatter & Validator shows the line number, character position, and highlights the problematic area in red.
IDE Tips: VS Code JSON Extensions
Visual Studio Code provides excellent JSON support out of the box, but these extensions make it even better:
- JSON Tools โ Format, minify, and sort JSON with keyboard shortcuts
- Paste JSON as Code โ Generate TypeScript interfaces from JSON samples
- JSON Crack โ Visualize JSON as interactive graphs
- JSON Schema Store โ Auto-complete and validation for common config files
VS Code built-in features:
- Format Document (
Shift+Alt+F) โ auto-formats JSON files - Bracket Pair Colorization โ visually match brackets (enable in settings)
- Error Squiggles โ red underlines show syntax errors in real-time
- JSON Schema validation โ add
"$schema"property for auto-completion
Command-Line JSON Tools
For terminal workflows and automation, these CLI tools are invaluable:
jq โ The Swiss Army Knife for JSON
Install: brew install jq (Mac) or apt install jq (Linux)
Python's json.tool
Node.js One-Liners
How to Fix JSON Automatically
Don't want to hunt for errors manually? Our Auto-Fix JSON tool detects and repairs many common errors automatically:
- Removes trailing commas
- Converts single quotes to double quotes
- Adds quotes to unquoted keys
- Fixes boolean/null casing
- Removes JavaScript-style comments
- Escapes unescaped characters
Just paste your broken JSON and click "Fix" โ the tool shows you exactly what it repaired.
You can also use our JSON Formatter & Validator to pinpoint the exact line and character where an error occurs, making manual fixes straightforward.
Prevention Tips
Avoid JSON errors in the first place with these practices:
- Use an editor with JSON syntax highlighting (VS Code, Sublime Text, JetBrains IDEs)
- Enable auto-format on save in your IDE
- Validate JSON before sending it to an API
- Use TypeScript or JSON Schema validation to catch errors at compile time
- Never manually edit minified JSON โ format it first, edit, then minify
- Use
JSON.stringify()to generate JSON instead of string concatenation - Set up pre-commit hooks to validate JSON config files
- Use environment-specific configs instead of commenting out JSON sections