Common JSON Syntax Errors and How to Fix Them
JSON is strict. Here are the mistakes that trip people up most often — each shown with an invalid example and the correct fix.
JSON (JavaScript Object Notation) is deliberately minimal, but that minimalism comes with strict rules. Unlike JavaScript object literals — which parsers handle loosely — JSON follows RFC 8259 exactly, with no tolerance for common JavaScript shorthand. The result is that JSON copied or generated from JavaScript code often contains errors a JSON parser will reject.
When you encounter a JSON parse error, the error message typically tells you the line and column number of the problem. Use the JSON Validator to locate it quickly. The errors below cover the vast majority of cases you'll encounter.
Error 1: Trailing comma
A trailing comma appears after the last element of an array or the last key-value pair of an object. This is allowed in JavaScript but forbidden in JSON.
// Invalid JSON — trailing comma after "editor"
{
"roles": ["admin", "editor",]
}
// Valid JSON — no trailing comma
{
"roles": ["admin", "editor"]
}
Trailing commas are common when you delete the last item from a list without removing its comma, or when you add an item to the end in JSON generated from code. If you frequently need trailing commas in config files, consider JSON5 or JSONC instead.
Error 2: Single quotes instead of double quotes
JSON requires double quotes for all keys and string values. Single quotes are valid JavaScript but invalid JSON.
// Invalid JSON
{'name': 'Alice', 'city': 'Paris'}
// Valid JSON
{"name": "Alice", "city": "Paris"}
This mistake usually comes from copying a JavaScript object literal directly into JSON, or from writing JSON by hand in a language where single quotes are the default string delimiter (like Python or Ruby). The fix is to replace all single quotes with double quotes — but be careful to escape any double quotes inside string values with a backslash.
Error 3: Unquoted keys
In JavaScript, object keys do not need quotes if they are valid identifiers. In JSON, every key must be a double-quoted string.
// Invalid JSON
{name: "Alice", age: 30}
// Valid JSON
{"name": "Alice", "age": 30}
Unquoted keys appear when developers hand-write JSON thinking of it as JavaScript, or copy-paste from console output.
Error 4: Comments
JSON does not support comments. Neither // single-line nor /* block */ comments are valid. This surprises many developers because JSON is often used for configuration files where comments seem natural.
// Invalid JSON — comments not allowed
{
// Server configuration
"host": "localhost",
"port": 8080 /* default port */
}
// Valid JSON — no comments
{
"host": "localhost",
"port": 8080
}
If you need comments in config files, the options are: JSONC (JSON with Comments, supported by VS Code), JSON5 (supports both comment styles plus trailing commas), or YAML. See the guide on JSON vs JSON5 vs JSONC.
Error 5: Invalid values (undefined, NaN, Infinity)
JSON supports exactly six value types: string, number, object, array, true, false, and null. JavaScript-specific values are not permitted.
// Invalid JSON
{
"score": NaN,
"ratio": Infinity,
"value": undefined
}
// Valid JSON — use null or a numeric substitute
{
"score": null,
"ratio": null,
"value": null
}
This is a common problem when serializing JavaScript objects to JSON using JSON.stringify(). JavaScript's JSON.stringify converts undefined and functions to null (or omits them from objects), and converts NaN and Infinity to null. The problem arises when JSON is written by hand or generated by a non-standard serializer.
Error 6: Mismatched brackets and braces
Every opening { must have a closing }, and every opening [ must have a closing ]. They must also be properly nested — you cannot close a brace before closing an array that started inside it.
// Invalid — missing closing }
{
"user": {
"name": "Alice"
}
Mismatched brackets are easier to spot in a formatted view than in minified JSON. If your validator points to the end of the file with an "unexpected end of input" error, a missing closing bracket is the most likely cause. Paste the JSON into the formatter first to make the structure visible, then find the imbalance.
Error 7: Unescaped special characters in strings
Certain characters inside a JSON string must be escaped with a backslash. The characters that must be escaped are: double quote (\"), backslash (\\), and control characters (newline as \n, tab as \t, etc.).
// Invalid — unescaped double quote and backslash
{"path": "C:\Users\Alice", "message": "She said "hello""}
// Valid — escaped
{"path": "C:\\Users\\Alice", "message": "She said \"hello\""}
Windows file paths are a frequent source of this error because backslashes must be doubled.
Error 8: Invalid number formats
JSON numbers must be standard decimal integers or decimals. Hexadecimal literals, numbers with leading zeros, and numbers without a leading digit before the decimal point are all invalid.
// Invalid number formats
{
"hex": 0xFF,
"octal": 0755,
"leading_zero": 007,
"no_leading_digit": .5
}
// Valid JSON
{
"hex": 255,
"octal": 493,
"value": 7,
"decimal": 0.5
}
How to quickly find and fix JSON errors
The fastest workflow for debugging a JSON error:
- Paste the JSON into the JSON Validator — it reports the exact line and column of the first error.
- If the error location is unclear, paste the JSON into the JSON Formatter first. Even with errors, the formatter can often display a partial structure that makes the problem visible.
- Fix the error the validator reported. If there are multiple errors, parsers typically stop at the first one — fix each in sequence.
- Re-validate until the JSON is clean.
Validate your JSON — free
Paste your JSON and get the exact error line and column instantly. No signup required.
Open JSON Validator →Frequently Asked Questions
Why does my JSON have a trailing comma error?
Standard JSON (RFC 8259) does not allow trailing commas after the last element of an array or object. Remove the comma after the final item. If you need trailing commas in config files, consider using JSON5 or JSONC instead.
Can JSON keys use single quotes?
No. JSON requires all keys and string values to use double quotes. Single quotes are valid in JavaScript object literals but are not permitted in JSON.
Can JSON have comments?
No. Comments are not part of the JSON specification (RFC 8259). If you need comments in a JSON-like config file, use JSON5 or JSONC, both of which allow // and /* */ style comments.
What values are allowed in JSON?
JSON allows six value types: string (double-quoted), number (integer or decimal, no hex or leading zeros beyond the integer part), boolean (true or false, lowercase), null, object, and array. JavaScript values like undefined, NaN, and Infinity are not valid JSON.