← Back to Blog

Common JSON Errors and How to Fix Them

March 9, 2026 6 min read By CodeTidy Team

JSON's syntax is simple, but that simplicity is deceptive — there are several places where a tiny mistake breaks the entire document. Here are the most common JSON errors, why they happen, and how to fix them fast.

1. Trailing Commas

This is the single most common JSON error. Unlike JavaScript, JSON does not allow trailing commas.

// INVALID - trailing comma after "SQL"
{
  "skills": ["Python", "Go", "SQL",]
}

// VALID
{
  "skills": ["Python", "Go", "SQL"]
}

Why it happens: JavaScript and most programming languages allow trailing commas. Developers write JSON the same way they write code. Some editors even auto-add trailing commas.

Fix: Remove the comma after the last item in every array and object. Our JSON Validator will point to the exact line.

2. Single Quotes Instead of Double Quotes

JSON requires double quotes for both keys and string values. Single quotes are invalid.

// INVALID - single quotes
{
  'name': 'Alice'
}

// VALID - double quotes
{
  "name": "Alice"
}

Why it happens: Python uses single quotes by default. JavaScript allows both. When developers copy data from a REPL or console, single quotes come along.

Fix: Find-and-replace single quotes with double quotes, but be careful with apostrophes inside strings (e.g., "it's"). Better: re-serialize using json.dumps() in Python or JSON.stringify() in JavaScript.

3. Unquoted Keys

Every key in JSON must be a double-quoted string. JavaScript shorthand doesn't apply.

// INVALID - unquoted keys
{
  name: "Alice",
  age: 30
}

// VALID
{
  "name": "Alice",
  "age": 30
}

Why it happens: JavaScript object literals allow unquoted keys. Copy-pasting from a JS console or writing JSON by hand without quotes is natural.

4. Comments

JSON does not support comments of any kind — no //, no /* */, no #.

// INVALID - comments not allowed
{
  "port": 3000,  // server port
  "debug": true  /* enable debug mode */
}

// VALID
{
  "port": 3000,
  "debug": true
}

Why it happens: It's natural to want to annotate configuration. Douglas Crockford (JSON's creator) deliberately omitted comments to prevent misuse of JSON as a configuration language — though that ship has sailed.

Workarounds:

  • Use a "_comment" key: "_comment": "This sets the server port"
  • Use JSON5 or JSONC (JSON with Comments) if your tooling supports it
  • Use YAML or TOML for config files that need comments

5. Leading Zeros on Numbers

// INVALID
{
  "zipcode": 07102,
  "count": 007
}

// VALID
{
  "zipcode": 7102,
  "count": 7
}

// Or keep as strings if leading zeros matter
{
  "zipcode": "07102",
  "count": 7
}

Why it happens: ZIP codes, product codes, and phone numbers often have leading zeros. In JSON, leading zeros make a number invalid (some parsers interpret them as octal).

Fix: If leading zeros are meaningful, store the value as a string.

6. Incorrect Boolean and Null Values

JSON booleans are lowercase true and false. The null value is lowercase null.

// INVALID
{
  "active": True,
  "admin": FALSE,
  "deleted": None,
  "value": undefined
}

// VALID
{
  "active": true,
  "admin": false,
  "deleted": null
}

Why it happens: Python uses True, False, and None (capitalized). Some languages use TRUE/FALSE. JavaScript's undefined doesn't exist in JSON.

Fix: Always use lowercase. Never include undefined — either use null or omit the key entirely.

7. Multiline Strings and Special Characters

// INVALID - literal newline inside string
{
  "bio": "Line one
  Line two"
}

// VALID - escaped newline
{
  "bio": "Line one\nLine two"
}

// INVALID - unescaped tab or backslash
{
  "path": "C:\new\folder"
}

// VALID - escaped backslashes
{
  "path": "C:\\new\\folder"
}

JSON strings must be on a single line. Special characters that need escaping:

CharacterEscape Sequence
Double quote\"
Backslash\\
Newline\n
Tab\t
Carriage return\r
Unicode\uXXXX

8. Missing or Extra Braces/Brackets

// INVALID - missing closing bracket
{
  "items": [1, 2, 3
}

// INVALID - extra closing brace
{
  "name": "Alice"
}}

// VALID
{
  "items": [1, 2, 3]
}

Fix: Use a JSON formatter with proper indentation — mismatched brackets become visually obvious when the structure is properly indented.

9. Duplicate Keys

// Technically parses but problematic
{
  "name": "Alice",
  "name": "Bob"
}

The JSON spec says duplicate keys produce "undefined" behavior. Most parsers silently take the last value ("Bob"), but some throw errors, and others take the first value. The result depends on which parser you use.

Fix: Always use unique keys. If you need multiple values, use an array.

How to Debug JSON Errors Quickly

  1. Paste into a validator — Use our JSON Validator to get the exact line and column of the error.
  2. Format it first — Minified JSON is nearly impossible to debug visually. Use a JSON Formatter to pretty-print it.
  3. Check the error message — Most parsers include a character position. Unexpected token at position 47 means look at the 47th character.
  4. Validate incrementally — If you have a large JSON file, try validating smaller sections to isolate the error.
  5. Use a JSON-aware editor — VS Code, JetBrains IDEs, and Sublime Text all highlight JSON syntax errors in real-time.

Most JSON errors come from treating it like a programming language instead of a strict data format. Remember: no trailing commas, double quotes only, no comments, lowercase booleans. Follow these rules and you'll avoid 95% of JSON parsing headaches.

Drop file to load