Common JSON syntax errors

Published 17 October 2026

JSON looks like JavaScript object literals, which is exactly why people write things that are valid JavaScript but not valid JSON. The grammar is defined by RFC 8259 and it is strict: no comments, no trailing commas, double quotes only.

The eight mistakes

  1. Trailing comma — tolerated by JavaScript, rejected by JSON.
    {"a": 1,}      invalid
    {"a": 1}       valid
  2. Comments — neither // nor /* */ is allowed. Put the note in a separate field, or in the documentation.
  3. Single quotes — strings must use double quotes.
    {"a": "x"}    valid
    {'a': 'x'}    invalid
  4. Unquoted keys —
    {"a": 1}      valid
    {a: 1}        invalid
  5. NaN, Infinity, undefined — none of these are JSON values. Use null or a string.
  6. Leading zeros — 012 is not a JSON number. Write 12, or quote it if it is an identifier such as a phone number.
  7. Raw control characters — a literal tab or newline inside a string must be escaped as \t or \n.
  8. A byte order mark or stray text before the opening brace. Some editors add a BOM; JSON parsers reject it.

Valid JSON that still surprises you

Finding the position

Modern engines report an offset, for example Unexpected token } in JSON at position 12 or Expected property name or '}' in JSON at position 1. The message is engine-specific, so do not build logic on its text — but the position is usually enough to find the offending character.

A quick checklist

  1. Does every brace and bracket have a partner?
  2. Is every key in double quotes?
  3. Is the last element in each object or array free of a comma?
  4. Are there comments anywhere?
  5. Are large identifiers quoted?

Paste the payload into the JSON formatter to see the reformatted output and the syntax errors. Formatting keeps comments and trailing commas; Minify removes them and outputs strict JSON. If the JSON is a request body, the cURL generator turns it into a command you can run.