Understanding JSON Syntax Errors and How to Fix Them

JSON has one job: be unambiguous. That strictness makes it reliable for machines but unforgiving for humans. If you've ever seen Unexpected token } in JSON, this guide is for you.

1. Trailing commas

The most common JSON mistake, usually from copy-pasting JavaScript. JSON forbids a comma after the last item.

{
  "name": "app",
  "port": 8080,
}

That trailing comma after 8080 is illegal.

Fix: Remove the comma before any closing } or ].

2. Single quotes

JavaScript allows 'single' quotes. JSON requires "double" quotes for every string and every key.

{ 'name': 'app' }

Fix: Replace all single quotes with double quotes: { "name": "app" }.

3. Unquoted keys

In JavaScript object literals you can write { name: "app" }. JSON requires keys to be quoted strings.

{ name: "app" }

Fix: Quote the key: { "name": "app" }.

4. Missing commas between items

Two values back-to-back without a comma produces Unexpected string or Unexpected number.

{
  "host": "localhost"
  "port": 5432
}

Fix: Add a comma after each item except the last: "host": "localhost",.

5. Comments

JSON does not support comments — not // and not /* */. This surprises people coming from almost any other config format.

{
  // this breaks
  "port": 8080
}

Fix: Remove the comment. If you genuinely need comments in config, use JSONC (a superset some tools accept), or switch to YAML or TOML, both of which support # comments.

6. undefined and NaN

JSON only knows null, not JavaScript's undefined or NaN.

{ "value": undefined }

Fix: Use null, or omit the key entirely.

7. Unclosed brackets

Every { needs a } and every [ needs a ]. A mismatch gives Unexpected end of JSON input.

Fix: Count your brackets. A formatter helps here — when you pretty-print, the indentation makes a missing bracket obvious.

Decoding the error messages

MessageUsual cause
Unexpected token } Trailing comma
Unexpected string / numberMissing comma between items
Unexpected token 'Single quotes
Unexpected end of JSON inputUnclosed bracket or brace
Unexpected token uA stray undefined

The fast fix

Instead of squinting at line numbers, paste your JSON into the validator. It highlights the exact line and column, explains the error in plain English, and tells you how to fix it. Once it's valid, switch to the formatter to pretty-print it with clean indentation.

Avoiding JSON errors for good

  • Never copy object literals straight from JS — they often have trailing commas and single quotes.
  • Use an editor with JSON syntax highlighting; it flags most issues live.
  • Validate before you commit or deploy.

JSON's strictness is a feature once you internalize the rules. These seven cover nearly every error you'll ever see.

Got a config file to check?

Open the config toolkit →