Back to Blog
·9 min read

How to Fix Common JSON Syntax Errors (With Real Examples)

A practical walkthrough of the most frequent JSON syntax errors — what causes them, what the error messages mean, and exactly how to fix each one.

If you work with JSON regularly, you've hit "Unexpected token in JSON" or "SyntaxError: Unexpected end of JSON input" more times than you can count. These errors are notoriously unhelpful — they tell you something is wrong, but rarely exactly what or where. This guide walks through the most common causes, shows you real examples of broken JSON, and explains exactly how to fix each one.

1. Trailing commas

This is by far the most common JSON error, especially for developers coming from JavaScript, where trailing commas are perfectly legal. JSON does not allow a comma after the last element in an array or the last property in an object.

// Broken — trailing comma after the last property
{
  "name": "Alice",
  "age": 30,
}

// Broken — trailing comma in an array
{
  "tags": ["admin", "user",]
}

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

The error message you'll typically see is something like "Unexpected token } in JSON at position 32" — the position points to right around the trailing comma or the closing brace that follows it.

2. Single quotes instead of double quotes

JSON strictly requires double quotes (") for both keys and string values. Single quotes are valid in JavaScript object literals and in Python dictionaries, which is why this mistake is so common when copying code between languages.

// Broken — single quotes
{
  'name': 'Alice',
  'role': 'admin'
}

// Fixed — double quotes
{
  "name": "Alice",
  "role": "admin"
}

The error usually appears as "Unexpected token ' in JSON at position 1" — right at the very first single quote the parser encounters.

3. Unquoted object keys

In JavaScript, object keys don't need quotes if they're valid identifiers. JSON has no such exception — every key must be a double-quoted string, no matter how simple it looks.

// Broken — unquoted keys
{
  name: "Alice",
  age: 30
}

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

4. Python literals: True, False, None

If you're generating JSON from Python by calling str() on a dict instead of using json.dumps(), you'll end up with Python's capitalized booleans and None instead of JSON's lowercase true, false, and null.

// Broken — Python literals
{
  "active": True,
  "deletedAt": None,
  "verified": False
}

// Fixed — JSON literals (always lowercase)
{
  "active": true,
  "deletedAt": null,
  "verified": false
}

Tip: In Python, always serialize with json.dumps(data) rather than str(data) — it produces spec-compliant JSON automatically.

5. Comments in JSON

Standard JSON has no concept of comments — not // and not /* */. They are extremely useful in config files though, which is why formats like JSONC (JSON with Comments) and JSON5 exist as supersets that allow them. A strict JSON parser will reject any file containing a comment.

// Broken — comments are not valid JSON
{
  // This is the user's display name
  "name": "Alice",
  "age": 30 /* in years */
}

// Fixed — comments removed
{
  "name": "Alice",
  "age": 30
}

6. Missing or extra commas between elements

Forgetting a comma between two properties — or accidentally adding an extra one — is an easy typo to miss when scanning a long document by eye.

// Broken — missing comma between "age" and "role"
{
  "name": "Alice"
  "age": 30,
  "role": "admin"
}

// Fixed
{
  "name": "Alice",
  "age": 30,
  "role": "admin"
}

7. Mismatched or missing brackets

A missing closing brace or bracket usually produces "Unexpected end of JSON input" — the parser reaches the end of the text while still expecting more content. This is common in deeply nested structures where it's easy to lose track of how many levels you need to close.

// Broken — missing closing brace for "address"
{
  "name": "Alice",
  "address": {
    "city": "Austin",
    "zip": "73301"
}

// Fixed
{
  "name": "Alice",
  "address": {
    "city": "Austin",
    "zip": "73301"
  }
}

Tip: A good code editor with bracket-matching and JSON syntax highlighting (like the Monaco editor used in our tools) will visually flag mismatched brackets as you type.

8. Leading zeros and other invalid number formats

JSON numbers follow stricter rules than you might expect: no leading zeros (except for the number 0 itself), no leading + sign, and no trailing decimal point without digits after it.

// Broken
{ "code": 0123, "rate": 1., "delta": +5 }

// Fixed
{ "code": "0123", "rate": 1.0, "delta": 5 }

Note that "0123" was changed to a string in the fix — if a value has meaningful leading zeros (like a US zip code or a product code), it should be stored as a string, not a number, regardless of JSON validity.

How to debug JSON errors faster

  • ·Read the error position carefully — most parsers report a character index or line/column number pointing close to the problem
  • ·Work from the inside out — fix the innermost nested structure first, then work outward
  • ·Use a validator that shows line and column numbers rather than relying on a generic try/catch
  • ·When JSON comes from an LLM or a hand-written source, expect trailing commas, comments, and quote mismatches — these are the most common LLM-generated JSON issues

JSON Validator

Paste your JSON and get the exact line and column number of every syntax error.

JSON Repair

Automatically fixes trailing commas, single quotes, unquoted keys, comments, and Python literals in one click.

When to repair vs. when to fix the source

Auto-repair tools are great for one-off debugging — inspecting a malformed API response, cleaning up an LLM-generated payload, or recovering a hand-edited config file. But if you control the code that produces the JSON, fix the root cause: use a proper serializer (json.dumps in Python, JSON.stringify in JavaScript) instead of string concatenation or naive type coercion. That way the error never reaches your users — or your logs — in the first place.

Tip: Bookmark the JSON Validator and JSON Repair tools — between them they cover almost every "why won't my JSON parse" situation you'll run into.

Ad