25 Broken JSON Examples and How to Fix Them
JSON parse errors are among the most frustrating bugs in web development — and they are almost always caused by the same small set of syntax mistakes. This comprehensive guide walks through 25 real broken JSON examples, explains exactly why each one fails, and shows the corrected version. Whether you are debugging an API response, fixing a config file, or learning JSON from scratch, these examples will sharpen your eye for errors instantly.
25
Broken JSON patterns covered
8
Root cause categories
100%
Browser-parseable fixes
5min
Time to master all patterns
Why JSON Breaks: The Root Causes
JSON (JavaScript Object Notation) is strict by design. Unlike JavaScript, it has no tolerance for comments, trailing commas, single quotes, or unquoted keys. Understanding the root cause categories helps you spot errors before you even run a parser.
Quote Errors
Single quotes, unescaped quotes, missing quotes around keys or string values.
Comma Errors
Trailing commas, double commas, missing commas between values.
Bracket Errors
Missing closing braces { }, brackets [ ], or mismatched pairs.
Invalid Values
NaN, Infinity, undefined, Date objects, comments — none are valid JSON.
Quick Reference: What JSON Does and Does Not Allow
Quote Errors: Examples 1–5
Single quotes — invalid JSON
{'name': 'John', 'age': 30}Double quotes — valid JSON
{"name": "John", "age": 30}JSON requires double quotes for all strings, both keys and values. Single quotes are valid in JavaScript but cause a parse error in any strict JSON parser.
Unquoted keys — JavaScript style, not JSON
{name: "John", age: 30}All keys must be double-quoted strings
{"name": "John", "age": 30}{"message": "He said "Hello""}
{"key": "value"}{"message": "He said \\"Hello\\""}
{"key": "value"}// BROKEN: unescaped inner quotes break the string boundary
{"message": "He said "Hello" to me"}
// FIXED: escape inner double quotes with backslash
{"message": "He said \"Hello\" to me"}{"text": "Line 1\nLine 2"} — raw newline in string
{"key": "value"}{"text": "Line 1\\nLine 2"} — escaped newline
{"key": "value"}// BROKEN: literal newline inside a JSON string
{"text": "Line 1
Line 2"}
// FIXED: use escape sequences
{"text": "Line 1\nLine 2"}
// Other common escapes:
// \t = tab
// \r = carriage return
// \\ = literal backslash
// \" = literal double quoteComma Errors: Examples 6–10
Trailing comma after last property — not valid in JSON
{"name": "John", "age": 30,}No comma after the final property
{"name": "John", "age": 30}Quick fact
Trailing commas are allowed in modern JavaScript (ES5+) and TypeScript, but are strictly forbidden in JSON. This is the #1 source of JSON errors when copy-pasting from JS code.
Trailing comma in array — invalid JSON
[1, 2, 3,]Clean array without trailing comma
[1, 2, 3]// BROKEN: missing comma between properties
{"name": "John" "age": 30}
// FIXED:
{"name": "John", "age": 30}
// BROKEN: double comma
{"name": "John",, "age": 30}
// FIXED:
{"name": "John", "age": 30}
// BROKEN: missing comma and missing quotes on key
{"name": "John" age: 30}
// FIXED:
{"name": "John", "age": 30}Bracket and Brace Errors: Examples 11–15
Missing closing brace — object never closed
{"users": [{"name": "John"}]All opened braces and brackets must be closed
{"users": [{"name": "John"}]}// BROKEN: array opened with [ but closed with }
{"items": [1, 2, 3}
// FIXED:
{"items": [1, 2, 3]}
// BROKEN: nested object missing closing brace
{"nested": {"key": "value"}
// FIXED:
{"nested": {"key": "value"}}
// BROKEN: array tag never closed
{"tags": ["red", "blue"]
// FIXED:
{"tags": ["red", "blue"]}
// BROKEN: multiple levels unclosed
{"a": {"b": [1, 2
// FIXED:
{"a": {"b": [1, 2]}}Bracket Counting Trick
Invalid Value Errors: Examples 16–20
NaN is not a valid JSON value
{"price": NaN}Use null to represent missing numeric values
{"price": null}Infinity is not a valid JSON value
{"count": Infinity}Use null or omit the field entirely
{"count": null}// BROKEN: undefined is a JS concept, not valid JSON
{"middleName": undefined}
// FIXED: use null
{"middleName": null}
// BROKEN: Date object is not a JSON primitive
{"date": new Date()}
// FIXED: use ISO 8601 string
{"date": "2026-03-25T00:00:00.000Z"}
// BROKEN: function values cannot be serialized to JSON
{"calculate": function() { return 42; }}
// FIXED: omit function fields or store as string description
{"calculate": "returns 42"}Structural Errors: Examples 21–25
Multiple root objects — JSON allows only one root value
{"a": 1}{"b": 2}Wrap in an array if you need multiple root-level objects
[{"a": 1}, {"b": 2}]// BROKEN: octal number literals not valid in JSON
{"code": 0123}
// FIXED: use decimal
{"code": 83}
// BROKEN: comments are not allowed in JSON
{
// This is a comment
"name": "John"
}
// FIXED: remove all comments
{
"name": "John"
}
// BROKEN: unquoted string value
{"key": value}
// FIXED: all string values must be double-quoted
{"key": "value"}
// BROKEN: boolean value with wrong case
{"active": True}
// FIXED: JSON booleans are lowercase only
{"active": true}| Item | JavaScript (lenient) | JSON (strict) |
|---|---|---|
| String quotes | Single or double quotes OK | Double quotes only |
| Object keys | Can be unquoted identifiers | Must be double-quoted strings |
| Trailing commas | Allowed in ES5+ | Not allowed |
| Comments | // and /* */ both work | No comments of any kind |
| Special values | undefined, NaN, Infinity | Only null, true, false |
| Date objects | new Date() works | Must be ISO string |
| Functions | Can be values | Not serializable |
| Boolean casing | True, False, TRUE work | Only true and false (lowercase) |
Quick Fix Reference: All 25 Patterns
Pattern 1: Single quotes
Replace all ' with " for strings and keys.
Pattern 2: Trailing comma (object)
Remove comma after last key-value pair.
Pattern 3: Unquoted keys
Wrap every key in double quotes.
Pattern 4: Missing comma
Add comma between every key-value pair.
Pattern 5: Missing closing brace
Match every { with a }.
Pattern 6: Unescaped inner quotes
Replace " inside strings with \".
Pattern 7: Comments
Remove all // and /* */ comments.
Pattern 8: NaN value
Replace NaN with null.
Pattern 9: Infinity
Replace Infinity with null.
Pattern 10: undefined value
Replace undefined with null.
Pattern 11: Trailing comma (array)
Remove comma after last array element.
Pattern 12: Date object
Replace new Date() with ISO 8601 string.
Pattern 13: Multiple root objects
Wrap all root objects in a single array.
Pattern 14: Octal number
Replace 0123-style with decimal equivalent.
Pattern 15: Literal newline in string
Replace newline with \n escape.
Pattern 16: Double comma
Remove duplicate comma.
Pattern 17: Missing closing bracket
Match every [ with a ].
Pattern 18: Nested missing brace
Check inner objects for unclosed { }.
Pattern 19: Trailing comma in nested array
Remove trailing comma in any nested array.
Pattern 20: Boolean + missing comma
Add comma and verify boolean is one value per key.
Pattern 21: Missing comma + missing quotes
Fix key quoting and add separator comma.
Pattern 22: Unescaped newline in string
Use \n escape sequence instead of literal newline.
Pattern 23: Empty object (valid)
{"data": {}} is actually valid JSON — empty objects are fine.
Pattern 24: Missing closing bracket (long array)
Count array elements and verify ] is present.
Pattern 25: Unquoted string value
Any non-number, non-boolean, non-null value must be quoted.
How to Debug JSON Errors Systematically
Copy JSON
Run JSON.parse()
Read error line/col
Check pattern list
Apply fix
Validate again
// Step 1: Try to parse and get the error location
try {
const data = JSON.parse(yourJsonString);
console.log('Valid!', data);
} catch (e) {
console.error('Parse error:', e.message);
// Output: "Unexpected token ' in JSON at position 1"
// The position number tells you WHERE the error is
}
// Step 2: Extract the problem area
const position = 42; // from error message
const snippet = yourJsonString.substring(
Math.max(0, position - 20),
Math.min(yourJsonString.length, position + 20)
);
console.log('Problem area:', snippet);
// Step 3: Use a JSON linter for complex structures
// jsonlint.com, jsonformatter.curiousconcept.com, or VSCodeVSCode JSON Validation
Frequently Asked Questions
Summary