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

1

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

Allowed: strings (double-quoted), numbers, booleans (true/false), null, arrays, objects. NOT allowed: single quotes, comments, trailing commas, undefined, NaN, Infinity, Date objects, functions, or unquoted keys.
2

Quote Errors: Examples 1–5

Single quotes — invalid JSON

❌ Bad
{'name': 'John', 'age': 30}

Double quotes — valid JSON

✅ Good
{"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

❌ Bad
{name: "John", age: 30}

All keys must be double-quoted strings

✅ Good
{"name": "John", "age": 30}

{"message": "He said "Hello""}

❌ Bad
{"key": "value"}

{"message": "He said \\"Hello\\""}

✅ Good
{"key": "value"}
jsonExample 3: Unescaped quotes inside strings
// 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

❌ Bad
{"key": "value"}

{"text": "Line 1\\nLine 2"} — escaped newline

✅ Good
{"key": "value"}
jsonExample 4 & 5: Newlines and special characters in strings
// 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 quote
3

Comma Errors: Examples 6–10

Trailing comma after last property — not valid in JSON

❌ Bad
{"name": "John", "age": 30,}

No comma after the final property

✅ Good
{"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

❌ Bad
[1, 2, 3,]

Clean array without trailing comma

✅ Good
[1, 2, 3]
jsonExamples 8–10: Missing commas and double commas
// 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}
4

Bracket and Brace Errors: Examples 11–15

Missing closing brace — object never closed

❌ Bad
{"users": [{"name": "John"}]

All opened braces and brackets must be closed

✅ Good
{"users": [{"name": "John"}]}
jsonExamples 12–15: Mixed bracket/brace mismatches
// 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

For every opening brace or bracket you see, there must be a matching closing one. Count: opened braces minus closed braces should equal zero. Same for brackets. Most IDEs have bracket matching built in — use it.
5

Invalid Value Errors: Examples 16–20

NaN is not a valid JSON value

❌ Bad
{"price": NaN}

Use null to represent missing numeric values

✅ Good
{"price": null}

Infinity is not a valid JSON value

❌ Bad
{"count": Infinity}

Use null or omit the field entirely

✅ Good
{"count": null}
jsonExamples 18–20: undefined, Date objects, and functions
// 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"}
6

Structural Errors: Examples 21–25

Multiple root objects — JSON allows only one root value

❌ Bad
{"a": 1}{"b": 2}

Wrap in an array if you need multiple root-level objects

✅ Good
[{"a": 1}, {"b": 2}]
jsonExamples 22–25: Octal numbers, comments, unquoted values, whitespace
// 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}
ItemJavaScript (lenient)JSON (strict)
String quotesSingle or double quotes OKDouble quotes only
Object keysCan be unquoted identifiersMust be double-quoted strings
Trailing commasAllowed in ES5+Not allowed
Comments// and /* */ both workNo comments of any kind
Special valuesundefined, NaN, InfinityOnly null, true, false
Date objectsnew Date() worksMust be ISO string
FunctionsCan be valuesNot serializable
Boolean casingTrue, False, TRUE workOnly true and false (lowercase)
7

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.

8

How to Debug JSON Errors Systematically

Copy JSON

Run JSON.parse()

Read error line/col

Check pattern list

Apply fix

Validate again

javascriptDebugging JSON errors in Node.js or browser console
// 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 VSCode

VSCode JSON Validation

In VSCode, files ending in .json automatically get JSON validation highlighting. For inline JSON strings, install the "JSON Tools" extension to format and validate JSON anywhere in your codebase.

Frequently Asked Questions

Summary

JSON errors fall into 5 categories: quote errors, comma errors, bracket errors, invalid values, and structural errors. Memorize the key rule: JSON is stricter than JavaScript. Double quotes everywhere, no trailing commas, no comments, no undefined/NaN/Infinity, and exactly one root value.