Saved

Utilix knowledge base

Common JSON Syntax Mistakes (and Quick Fixes)

Published May 1, 2026

JSON has a simple grammar, but its strictness catches developers off-guard — especially those coming from JavaScript, Python, or YAML where the rules are looser. Here are the most common errors and how to fix each one.

1. Trailing commas

JSON does not allow a comma after the last item in an object or array. JavaScript and most modern languages do; JSON does not.

// ✗ Invalid
{ "name": "Alice", "age": 30, }

// ✓ Valid
{ "name": "Alice", "age": 30 }

Fix: Remove the final comma. Editors with JSON-aware linting (VS Code, IntelliJ) highlight these automatically.

2. Single-quoted strings

All strings — both keys and values — must use double quotes. Single quotes are a JavaScript convenience that JSON does not support.

// ✗ Invalid
{ 'name': 'Alice' }

// ✓ Valid
{ "name": "Alice" }

3. Unquoted or numeric keys

Keys must be strings. You cannot use bare identifiers or numbers as keys.

// ✗ Invalid
{ name: "Alice", 1: "value" }

// ✓ Valid
{ "name": "Alice", "1": "value" }

4. Comments

JSON has no comment syntax. Adding // or /* */ causes a parse error.

// ✗ Invalid — this will fail
{
  // user record
  "name": "Alice"
}

Fix: Strip comments before sending to an API. In editors, use JSONC (JSON with Comments) for configuration files that support it (VS Code settings.json, tsconfig.json).

5. Undefined and non-JSON values

undefined, NaN, Infinity, and -Infinity are not valid JSON values. They are JavaScript-specific.

// ✗ Invalid
{ "value": undefined, "ratio": NaN, "limit": Infinity }

// ✓ Valid alternatives
{ "value": null, "ratio": null, "limit": 1e308 }

6. Unescaped special characters in strings

Control characters (newline, tab, backspace) must be escaped with a backslash sequence inside a JSON string.

CharacterEscape
Newline\n
Tab\t
Backslash\\
Double quote\"
Null byte

7. Numbers with leading zeros

007 is not a valid JSON number. Use 7.

Quick debug workflow

  1. Paste the broken JSON into the JSON Formatter — it highlights the first parse error with a line number
  2. Fix that error, re-paste — JSON has cascading errors, so fix one at a time
  3. Once valid, use the formatter to pretty-print and inspect structure

Read What Is JSON? for the full grammar specification and data type reference.