Common JSON Formatting Mistakes & How to Fix Them

The errors that break JSON parsers, with examples and fixes for each.

JSON (JavaScript Object Notation) is deliberately simple, but its strictness catches many developers by surprise — especially those used to the more relaxed syntax of JavaScript object literals. A single misplaced comma or missing quote will cause the entire parse to fail. Here are the most common JSON errors, exactly what causes them, and how to fix them.

1. Trailing Commas

The most common JSON error. A comma after the last item in an object or array is invalid JSON.

// ❌ INVALID — trailing comma after "Alice"
{
  "name": "Alice",
  "age": 30,
}

// ✅ VALID — no trailing comma
{
  "name": "Alice",
  "age": 30
}

// ❌ INVALID — trailing comma in array
["red", "green", "blue",]

// ✅ VALID
["red", "green", "blue"]

Why it happens: JavaScript and most modern languages allow trailing commas in arrays and objects. Developers copy-paste or write by habit. Fix: Remove the comma from the last item.

2. Single Quotes Instead of Double Quotes

// ❌ INVALID — single quotes
{'name': 'Alice', 'age': 30}

// ✅ VALID — double quotes everywhere
{"name": "Alice", "age": 30}

JSON requires double quotes for all strings — keys and values. Single quotes are valid in JavaScript but invalid JSON.

3. Unquoted Keys

// ❌ INVALID — unquoted key
{name: "Alice"}

// ✅ VALID — key in double quotes
{"name": "Alice"}

In JavaScript, object keys can be unquoted if they are valid identifiers. JSON requires all keys to be quoted strings.

4. Comments

// ❌ INVALID — JSON has no comment syntax
{
  // This is the user object
  "name": "Alice",
  /* age in years */
  "age": 30
}

// ✅ VALID — no comments, or use a _comment field workaround
{
  "_comment": "This is the user object",
  "name": "Alice",
  "age": 30
}

JSON has no comment syntax. If you need annotated config files, consider JSON5, JSONC (VS Code uses this), or YAML instead.

5. Wrong Values for Booleans and Null

// ❌ INVALID — capitalised or quoted
{"active": True}
{"active": "true"}
{"value": NULL}
{"value": None}   // Python None is not JSON null

// ✅ VALID — lowercase, unquoted
{"active": true}
{"active": false}
{"value": null}

6. Unsupported Data Types

// ❌ INVALID — undefined, NaN, Infinity, functions
{"value": undefined}
{"score": NaN}
{"limit": Infinity}
{"fn": function() {}}

// ✅ VALID alternatives
{"value": null}           // undefined → null
{"score": null}           // NaN → null or omit
{"limit": 9999999}        // Infinity → max integer or omit
// Functions cannot be represented in JSON

JSON supports exactly six types: string, number, boolean, null, object, array. Dates are represented as ISO 8601 strings: "2026-06-16T10:00:00Z".

7. Unescaped Special Characters in Strings

// ❌ INVALID — unescaped double quote inside a string
{"message": "He said "hello""}

// ✅ VALID — escaped with backslash
{"message": "He said \"hello\""}

// ✅ Other escape sequences in JSON strings:
// \\ — backslash
// \/ — forward slash (optional)
// \n — newline
// \r — carriage return
// \t — tab
// \uXXXX — Unicode character

8. Numbers with Leading Zeros

// ❌ INVALID — leading zero
{"postcode": 01234}

// ✅ VALID — use a string for postcodes/phone numbers
{"postcode": "01234"}

JSON does not allow numbers with leading zeros (except 0 itself and 0.5 etc). For identifiers like postcodes or phone numbers that start with 0, always use strings.

Quick Check: Use a JSON Validator

If you receive a JSON parse error and cannot spot the issue manually, paste your JSON into the JSON Formatter & Validator. It highlights the exact character position of errors, making them easy to find in large payloads.

Advertisement

Frequently Asked Questions

Why does JSON not allow trailing commas?

The JSON specification (ECMA-404) strictly prohibits them. Standard parsers throw an error on trailing commas. Remove the comma from the last item in any object or array.

Can JSON keys be unquoted?

No — all keys must be in double quotes. Unquoted keys are valid JavaScript but invalid JSON. Write {"name": "Alice"} not {name: "Alice"}.

Does JSON allow single quotes?

No. JSON requires double quotes for all keys and string values. Single quotes cause a parse error.

Can I add comments to JSON?

No — JSON has no comment syntax. Use JSONC, JSON5, or YAML if you need comments in config files. As a workaround, add a "_comment" key field in your JSON.

What data types does JSON support?

Six types: string (double quotes), number, boolean (true/false lowercase), null (lowercase), object, and array. No undefined, NaN, Infinity, dates (use ISO 8601 strings), or functions.