Common JSON Syntax Errors and How to Fix Them
JSON's strict syntax rules mean that even a small mistake will cause a parsing error. Unlike JavaScript, JSON has no tolerance for trailing commas, single quotes, or unquoted keys. This guide covers the most frequent errors developers encounter and how to fix each one.
Trailing Commas
The most common JSON error is a trailing comma after the last item in an object or array. JavaScript allows this, but JSON does not.
// ❌ Invalid — trailing comma
{"name": "John", "age": 30,}
// ✅ Valid — no trailing comma
{"name": "John", "age": 30}Single Quotes Instead of Double Quotes
JSON requires double quotes for all strings and keys. Single quotes, backticks, or unquoted keys are not valid.
// ❌ Invalid — single quotes
{'name': 'John'}
// ✅ Valid — double quotes
{"name": "John"}Comments in JSON
Standard JSON does not support any form of comments. If you paste JSON that contains // or /* */ comments, the parser will fail. Remove all comments before parsing, or use a JSONC-aware parser.
// ❌ Invalid — comments not allowed
{
// This is a comment
"name": "John"
}
// ✅ Valid — no comments
{"name": "John"}Unquoted Keys
In JavaScript objects, keys without special characters don't need quotes. In JSON, every key must be a double-quoted string — no exceptions.
// ❌ Invalid — unquoted key
{name: "John"}
// ✅ Valid — quoted key
{"name": "John"}Incorrect Value Types
JSON only supports specific value types. Common mistakes include using undefined, NaN, Infinity, or functions — none of which are valid in JSON.
// ❌ Invalid values
{"value": undefined}
{"value": NaN}
{"value": Infinity}
// ✅ Use null for missing values
{"value": null}How to Debug JSON Errors
When you encounter a JSON parsing error, try these steps:
- Paste your JSON into the JSON Formatter — it will show the exact error location
- Check for trailing commas, especially after copy-pasting from code
- Verify all strings use double quotes, not single quotes or backticks
- Remove any comments (
//or/* */) - Ensure all values are valid JSON types (no
undefined,NaN, or functions)
Try These Tools
Frequently Asked Questions
Why doesn't JSON support comments?
Douglas Crockford, who specified JSON, deliberately omitted comments to keep the format simple and to prevent abuse of comments for parsing directives. For files that need comments, consider YAML or JSONC.
Can I validate JSON without a tool?
You can use JSON.parse() in any browser's developer console. If it throws a SyntaxError, the JSON is invalid. The error message will often indicate the position of the problem.