JSON has strict syntax rules. Unlike HTML, which browsers will try to repair, or JavaScript, which has flexible parsing, JSON parsers reject any document that does not conform to the spec. A single character out of place means the entire file fails.
The good news: JSON errors are almost always easy to fix once you know what to look for.
Error 1: Trailing Comma
Error message:SyntaxError: Unexpected token } or Trailing comma not allowed
// Broken
{
"name": "Alice",
"age": 30, โ extra comma
}
// Fixed
{
"name": "Alice",
"age": 30
}This is the most common JSON error. JavaScript and Python both allow trailing commas in their object literals, so developers who write JSON by hand often forget that JSON does not.
Quick fix: Remove the comma after the last property in any object or array.
Error 2: Single Quotes Instead of Double Quotes
Error message:SyntaxError: Unexpected token '
// Broken
{ 'name': 'Alice' }
// Fixed
{ "name": "Alice" }JSON requires double quotes for both keys and string values. Single quotes are valid in JavaScript and Python but are not permitted anywhere in JSON.
Quick fix: Replace all single quotes ' with double quotes ". In VS Code: Ctrl+H โ replace ' with " (be careful not to replace apostrophes inside string values).
Error 3: Unquoted Keys
Error message:SyntaxError: Unexpected token n (or the first letter of your key)
// Broken โ valid JavaScript object but invalid JSON
{
name: "Alice",
age: 30
}
// Fixed
{
"name": "Alice",
"age": 30
}In JavaScript, object keys can be unquoted if they are valid identifiers. In JSON, all keys must be quoted strings โ no exceptions.
Error 4: Missing Comma Between Elements
Error message:SyntaxError: Unexpected string or Unexpected token {
// Broken โ missing comma between objects
[
{ "name": "Alice" }
{ "name": "Bob" } โ needs a comma before this
]
// Fixed
[
{ "name": "Alice" },
{ "name": "Bob" }
]Every element in an array and every property in an object must be separated by a comma. Missing commas are common when manually editing JSON and adding or removing elements.
Error 5: Mismatched or Missing Brackets
Error message:SyntaxError: Unexpected end of JSON input
// Broken โ missing closing bracket on the array
{
"users": [
{ "name": "Alice" },
{ "name": "Bob" }
} โ array never closed
// Fixed
{
"users": [
{ "name": "Alice" },
{ "name": "Bob" }
]
} Every opening { needs a matching }, and every [ needs a ]. In large JSON files, bracket mismatches are hard to spot manually โ use a formatter or validator to highlight unmatched brackets automatically.
Error 6: Comments in JSON
Error message:SyntaxError: Unexpected token /
// Broken โ JSON does not support comments
{
// This is the user record
"name": "Alice",
"age": 30 /* age in years */
}
// Fixed โ remove all comments
{
"name": "Alice",
"age": 30
} JSON does not support any form of comments โ not // single line and not /* block */. Remove all comments before parsing.
Error 7: Undefined, NaN, or Infinity Values
Error message:SyntaxError: Unexpected token u (for undefined) or n (for NaN)
// Broken โ these are JavaScript values, not JSON
{
"score": NaN,
"ratio": Infinity,
"data": undefined
}
// Fixed โ use valid JSON representations
{
"score": null,
"ratio": 1.7976931348623157e+308,
"data": null
} JSON does not have undefined, NaN, or Infinity. Replace them with null or an appropriate numeric representation.
Error 8: Control Characters in Strings
Error message:SyntaxError: Invalid character or Bad control character in string literal
Strings in JSON must not contain raw control characters (ASCII codes 0โ31) such as literal tab characters, newlines, or null bytes. These must be escaped:
| Character | JSON Escape Sequence |
|---|---|
| Newline | \n |
| Tab | \t |
| Carriage return | \r |
| Backslash | \\ |
| Double quote | \" |
Error 9: Duplicate Keys
Technically, JSON with duplicate keys is not rejected by most parsers โ it is parsed, but the behavior is undefined. Different parsers use different values (last wins, first wins, or error). The result is unpredictable:
// Ambiguous โ two "name" keys
{
"name": "Alice",
"name": "Bob" โ duplicate key
}Fix: Ensure all keys within an object are unique. If you need multiple values, use an array.
How to Find and Fix Errors Quickly
- Use a JSON validator โ paste your JSON into JSONLint or run
python -m json.tool file.json. Both show the exact line and character of the first error. - Format first โ run the JSON through a formatter before validating. Proper indentation makes structural issues (missing brackets, misplaced commas) visually obvious.
- Check the line before the error โ JSON parsers report errors at the point where parsing fails, not necessarily where the mistake is. A missing comma on line 5 will often be reported as an error on line 6.
- Use VS Code โ VS Code highlights JSON errors in real-time with red underlines and a tooltip explaining the problem.
Ready to Convert Your JSON?
Our converter validates your JSON before converting โ bad files are caught before they cause issues.
Convert JSON to Excel Now โ