Common JSON Errors & How to Fix Them

A complete guide to every common JSON syntax error. Each entry includes the exact error message, why it happens, and a before/after example showing how to fix invalid JSON. Use the JSON validator to detect and locate errors automatically.

error

Trailing Comma

Very Common
SyntaxError: Unexpected token } in JSON

JSON does not allow a comma after the last element in an object or array. This is the single most common JSON syntax error because JavaScript allows trailing.

cancel Invalid JSON

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

check_circle Fixed JSON

{
  "name": "Alice",
  "age": 30
}
lightbulb

Fix: Remove the comma after the last key-value pair before the closing } or ].

error

Unquoted Object Keys

Very Common
SyntaxError: Unexpected token n in JSON

All JSON object keys must be enclosed in double quotes. JavaScript object literals allow unquoted keys, but JSON requires every key to be a quoted string.

cancel Invalid JSON

{
  name: "Alice",
  age: 30
}

check_circle Fixed JSON

{
  "name": "Alice",
  "age": 30
}
lightbulb

Fix: Wrap every object key in double quotes.

error

Single-Quoted Strings

Common
SyntaxError: Unexpected token ' in JSON

JSON requires double quotes (") for all strings — both keys and values. Single quotes are a JavaScript convention not valid in JSON.

cancel Invalid JSON

{
  'name': 'Alice',
  'city': 'London'
}

check_circle Fixed JSON

{
  "name": "Alice",
  "city": "London"
}
lightbulb

Fix: Replace all single quotes with double quotes.

error

undefined, NaN, or Infinity Values

Common
SyntaxError: Unexpected token u in JSON

JSON only supports six data types: string, number, object, array, boolean, and null.

cancel Invalid JSON

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

check_circle Fixed JSON

{
  "value": null,
  "score": null,
  "limit": null
}
lightbulb

Fix: Replace undefined, NaN, and Infinity with null or a numeric literal.

error

Comments in JSON

Moderate
SyntaxError: Unexpected token / in JSON

Standard JSON does not support comments. This is by design — JSON is a data-interchange format, not a config language.

cancel Invalid JSON

{
  // user profile
  "name": "Alice",
  "age": 30 /* in years */
}

check_circle Fixed JSON

{
  "name": "Alice",
  "age": 30
}
lightbulb

Fix: Remove all comments. For config files that need comments, use JSONC or JSON5 format instead.

error

Unquoted String Values

Moderate
SyntaxError: Unexpected token A in JSON

String values in JSON must be wrapped in double quotes. Bare words are only valid for the keywords true, false, and null.

cancel Invalid JSON

{
  "status": active,
  "role": admin
}

check_circle Fixed JSON

{
  "status": "active",
  "role": "admin"
}
lightbulb

Fix: Wrap all string values in double quotes. Only true, false, and null can be unquoted.

error

Missing Comma Between Properties

Moderate
SyntaxError: Unexpected string in JSON

Every property in a JSON object and every element in a JSON array must be separated by a comma.

cancel Invalid JSON

{
  "name": "Alice"
  "age": 30
}

check_circle Fixed JSON

{
  "name": "Alice",
  "age": 30
}
lightbulb

Fix: Add a comma after every property except the last one.

error

Unescaped Special Characters

Less Common
SyntaxError: Bad escaped character in JSON

Certain characters inside JSON strings must be escaped with a backslash: double quote (\"), backslash (\\), and control characters like newline (\n) and tab (\t).

cancel Invalid JSON

{
  "path": "C:\Users\Alice",
  "message": "He said "hello""
}

check_circle Fixed JSON

{
  "path": "C:\\Users\\Alice",
  "message": "He said \"hello\""
}
lightbulb

Fix: Escape backslashes as \\ and double quotes inside strings as \".

JSON Linter vs JSON Validator

A JSON linter and a JSON validator refer to the same type of tool — both check whether JSON conforms to the RFC 8259 specification. "Linter" is borrowed from code quality tools; "validator" is the more formal term used in the JSON ecosystem. Both catch the same json syntax errors listed on this page.

If you need to validate json schema (checking whether values conform to a JSON Schema definition, not just whether the JSON is well-formed), you need a JSON Schema validator — a different tool that works on top of a valid JSON string.

Use the free JSON validator arrow_forward
Common JSON Errors & How to Fix Them