JSON ยท Debugging

Common JSON syntax errors

Learn to spot common JSON mistakes and fix invalid data with clear before-and-after examples.

JSON looks simple, but it is strict. One missing character can turn a valid payload into an invalid one. In practice, most JSON errors are caused by the same few mistakes: missing commas, trailing commas, unquoted keys, mismatched brackets, and broken string quotes.

When a parser says invalid JSON, the problem is usually close to the spot where the error is reported. Scan the previous few lines and check the object structure before you assume the whole payload is broken.

1. Missing comma between fields

Object properties must be separated by commas.

{
  "name": "Asha"
  "email": "asha@example.com"
}

This fails because the comma between "name" and "email" is missing.

{
  "name": "Asha",
  "email": "asha@example.com"
}

2. Trailing commas

JSON does not allow a trailing comma before the closing brace or bracket.

{
  "id": 101,
  "name": "Asha",
}

The correct version removes the final comma:

{
  "id": 101,
  "name": "Asha"
}

The same rule applies to arrays:

{
  "tags": ["php", "sql", "json",]
}

Remove the final comma to fix it:

{
  "tags": ["php", "sql", "json"]
}

3. Unquoted keys

JSON object keys must always be wrapped in double quotes.

{
  name: "Asha",
  email: "asha@example.com"
}

Correct format:

{
  "name": "Asha",
  "email": "asha@example.com"
}

4. Unquoted string values

String values also need double quotes. Numbers and booleans can be unquoted, but text cannot.

{
  "name": Asha,
  "active": true
}

Fix it by quoting the string:

{
  "name": "Asha",
  "active": true
}

5. Quotes inside strings

If a text value contains a quote character, escape it with a backslash.

{
  "message": "He said, "hello" to everyone."
}

Correct version:

{
  "message": "He said, \"hello\" to everyone."
}

6. Missing closing braces or brackets

JSON must be balanced. Every { needs a closing }, and every [ needs a closing ].

{
  "customer": {
    "id": 101,
    "name": "Asha"
}

Close the object before the final brace:

{
  "customer": {
    "id": 101,
    "name": "Asha"
  }
}

7. Using single quotes

JSON does not allow single quotes around strings or keys.

{
  'name': 'Asha'
}

Use double quotes instead:

{
  "name": "Asha"
}

8. Invalid numeric format

Numbers must be valid JSON numbers. A decimal should not have a second dot, and scientific notation must be complete.

{
  "price": 12.34.56,
  "rate": 1e
}

Correct version:

{
  "price": 12.3456,
  "rate": 1e3
}

9. Comments inside JSON

JSON does not allow comments. If you copy data from a JavaScript file, remove comment syntax before trying to parse it.

{
  // this is a comment
  "name": "Asha"
}

Use this instead:

{
  "name": "Asha"
}

Quick debugging checklist

  • Check that every opening brace or bracket has a matching closing character.
  • Make sure keys and string values use double quotes.
  • Remove trailing commas.
  • Verify commas separate entries, but do not place one after the last item.
  • Escape inner quotes inside strings.
  • Look at the character just before the parser error; it is often the actual problem.

Before and after example

Here is a small payload with several issues:

{
  "customer": {
    "id": 101
    "name": "Asha",
    "active": true,
    "tags": ["new", "student",],
  }
}

Fixed version:

{
  "customer": {
    "id": 101,
    "name": "Asha",
    "active": true,
    "tags": ["new", "student"]
  }
}

JSON is strict, but the rules are simple. Once you check commas, quotes, and nesting, most invalid payloads become obvious. That makes JSON far easier to debug when it is used in APIs, frontend forms, config files, and data exports.