Common JSON Errors & How to Fix Them

JSON parsing errors can be frustrating, especially when the error messages are cryptic. This guide covers the most common JSON errors, explains why they happen, and shows you exactly how to fix them.

1. Trailing Commas

One of the most frequent JSON errors. Unlike JavaScript, JSON does not allow trailing commas after the last element in an object or array.

❌ Invalid

{
    "name": "John",
    "age": 30,
    "city": "New York",
}

✅ Fixed

{
    "name": "John",
    "age": 30,
    "city": "New York"
}

2. Single Quotes Instead of Double Quotes

JSON strictly requires double quotes for strings and keys. Single quotes are not valid.

❌ Invalid

{
    'name': 'John Doe',
    'age': 30
}

✅ Fixed

{
    "name": "John Doe",
    "age": 30
}

3. Unquoted Property Names

All property names (keys) in JSON must be enclosed in double quotes. This is different from JavaScript objects where unquoted keys are allowed.

❌ Invalid

{
    name: "John",
    age: 30
}

✅ Fixed

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

4. Comments in JSON

Standard JSON does not support comments. This is a deliberate design decision by Douglas Crockford to keep the format simple and interoperable.

❌ Invalid

{
    "name": "John", // user's name
    "age": 30 /* user's age */
}

✅ Fixed

{
    "name": "John",
    "age": 30
}
Tip: If you need comments in config files, consider using JSONC (JSON with Comments) or JSON5, which are supported by tools like VS Code.

Advertisement

5. Missing or Extra Brackets

Mismatched curly braces {} or square brackets [] are a common source of errors, especially in large JSON files.

❌ Invalid — Missing closing bracket

{
    "users": [
        {"name": "John"},
        {"name": "Jane"}
}

✅ Fixed

{
    "users": [
        {"name": "John"},
        {"name": "Jane"}
    ]
}

6. Incorrect Use of Escape Characters

Special characters in strings must be properly escaped with a backslash.

❌ Invalid — Unescaped characters

{
    "path": "C:\new\folder\test",
    "message": "He said "hello""
}

✅ Fixed

{
    "path": "C:\\new\\folder\\test",
    "message": "He said \"hello\""
}

Valid Escape Sequences

SequenceCharacter
\"Double quote
\\Backslash
\/Forward slash
\bBackspace
\fForm feed
\nNewline
\rCarriage return
\tTab
\uXXXXUnicode character

7. Using undefined or NaN

JSON does not support undefined, NaN, Infinity, or -Infinity. These are JavaScript-specific values.

❌ Invalid

{
    "value": undefined,
    "result": NaN,
    "limit": Infinity
}

✅ Fixed

{
    "value": null,
    "result": null,
    "limit": null
}

8. Duplicate Keys

While technically not a syntax error (most parsers accept it), duplicate keys lead to unpredictable behavior as different parsers handle them differently.

⚠️ Problematic

{
    "name": "John",
    "age": 30,
    "name": "Jane"
}

✅ Fixed

{
    "name": "Jane",
    "age": 30
}

9. Leading Zeros in Numbers

JSON does not allow leading zeros in numbers. The only exception is 0 itself and numbers like 0.5.

❌ Invalid

{
    "zipCode": 01234,
    "price": 007.99
}

✅ Fixed

{
    "zipCode": "01234",
    "price": 7.99
}

Quick Debugging Checklist

  1. Check for trailing commas after the last element
  2. Ensure all strings use double quotes
  3. Verify all keys are quoted
  4. Remove any comments
  5. Match all opening and closing brackets
  6. Escape special characters properly
  7. Replace undefined, NaN, and Infinity with null
  8. Check for duplicate keys
  9. Remove leading zeros from numbers
Having trouble with JSON errors? Use our free JSON Validator to instantly find and fix issues!