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)
A quick checklist before you debug
When JSON refuses to parse, the cause is almost always mechanical rather than mysterious. Before you reach for a debugger, run through a short checklist. Are all keys and string values wrapped in double quotes rather than single ones? Is there a stray comma after the last item in an object or array? Does every opening brace and bracket have a matching close?
Two more issues catch most of the rest. Comments are not allowed in standard JSON, so a helpful note pasted from code will break the parse. And special characters inside strings, such as a literal newline or an unescaped backslash, need to be escaped. A formatter that validates as it goes will point at the exact line, which is faster than reading the whole file.
If the data comes from an API and still will not parse, check that you are looking at the response body and not the headers, and that it was not truncated in transit. Copying the raw payload into a validator removes any doubt about what the parser actually received.
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.
Why does my JSON work in JavaScript but fail in a strict parser?
JavaScript object literals are more forgiving than JSON. They allow single quotes, unquoted keys, trailing commas, and comments. A strict JSON parser rejects all of those, which is why code that looks fine can still fail validation.
What is the fastest way to find the exact error?
Paste the text into a validating editor. It highlights the first line and column where parsing breaks, so instead of scanning the whole document you can jump straight to the problem.