ToolSite

Common JSON Syntax Errors and How to Fix Them

Five common JSON syntax errors and how to fix them fast: trailing commas, unquoted keys, single quotes, comments, missing commas. Use our free validator.

By ToolSite4 min readguides

JSON Syntax Is Strict on Purpose

JSON's syntax rules are simple but absolute. Unlike JavaScript, which tolerates trailing commas and unquoted keys, JSON rejects anything that does not match the spec exactly. One stray comma and the entire document fails to parse.

The errors are always the same few, and you can fix them in seconds if you know what to look for. Most JSON parse failures come down to five mistakes. Once you recognize the patterns, debugging becomes mechanical.

Error 1: Trailing Commas

The most common JSON mistake by a wide margin. A trailing comma after the last element in an array or the last key-value pair in an object:

{
  "name": "Alice",
  "email": "alice@example.com",
}

That comma after "alice@example.com" is illegal. The parser sees it and throws a syntax error because it expects another key-value pair, not }.

Same problem in arrays:

["apple", "banana", "cherry",]

Fix: remove the trailing comma. If you're generating JSON from code, most serializers handle this automatically. If you're writing JSON by hand, a linter or formatter will catch it immediately. This error is especially common when you copy a line, paste it, and forget to remove the comma from the original last line.

Error 2: Unquoted Keys

In JavaScript, {name: "Alice"} is valid. In JSON, it is not. Every key must be a double-quoted string:

{
  name: "Alice",
  "email": "alice@example.com"
}

The parser reads name and has no idea what to do with it. It expected a string.

Fix: double-quote every key. Not single quotes. Double quotes only. This bites people coming from JavaScript or Python where unquoted or single-quoted keys are common. If you're copying a JavaScript object literal into a JSON file, wrap every key in double quotes before you save.

Error 3: Single-Quoted Strings

JSON only accepts double quotes for strings. Using single quotes produces a parse error:

{
  "message": 'hello world'
}

Fix: use "hello world". If your string contains double quotes, escape them with \". If you're copying JSON from a language that tolerates single quotes (Python, JavaScript in non-strict mode), run it through a validator first. This error is common when you're hand-writing JSON after spending the day writing Python or JavaScript, where single quotes are idiomatic.

Error 4: Comments in JSON

JSON has no comment syntax. None. No //, no /* */, no #. Any text that is not part of a valid string or value breaks the parser:

{
  // User's display name
  "name": "Alice"
}

Fix: remove comments before parsing. If you need comments in a config format, use YAML or JSONC (JSON with Comments, supported by VS Code). Standard JSON parsers will choke on both styles of comment. Some developers keep a separate README or schema file that documents each field instead of embedding comments.

This error often appears when developers start with a commented template, then try to parse it without stripping comments. Build tools like Webpack and esbuild can strip comments during bundling, but raw Node.js JSON.parse() cannot.

Error 5: Missing or Extra Commas

Forgetting a comma between array elements or object members is a syntax error:

{
  "name": "Alice"
  "email": "alice@example.com"
}

Missing comma between "Alice" and "email". The parser sees the newline as a separator and then hits "email" where it expected , or }.

Conversely, an extra comma with nothing after it:

{
  "name": "Alice",,
  "email": "alice@example.com"
}

Fix: commas separate items. Exactly one comma between each pair of adjacent members. If your editor supports JSON syntax highlighting, missing commas are usually flagged with a red underline before you even try to parse.

Other Common Issues

  • Unescaped backslashes: a string like "C:\Users\name" contains invalid escape sequences. Backslashes in JSON must be doubled: "C:\\Users\\name".
  • Bare special values: NaN, Infinity, and undefined are not valid JSON. JavaScript's JSON.stringify() converts NaN and Infinity to null, and drops undefined values entirely.
  • Non-string keys from JSON.stringify: if you pass a JavaScript Map or an object with a toJSON() method to JSON.stringify, the output may surprise you. Always inspect the serialized output before saving.

Quick Debugging Workflow

When a JSON parse fails:

  1. Paste the JSON into a JSON Validator. It will tell you the exact line and column of the error.
  2. If the error is on line 100 but the problem started on line 90 (missing closing bracket), work backward from the error position.
  3. If the JSON is minified, run it through a JSON Formatter first to make the structure visible. A single-line JSON blob hides mismatched braces and brackets.
  4. After fixing, format the JSON again and diff against the original to confirm the fix didn't change semantics.

Try it yourself: open the JSON Validator and paste this intentionally broken JSON: {"name": "Alice",}. The validator will flag the trailing comma at position 17. Then fix it, remove the comma, and validate again to see the clean pass. Use the JSON Formatter to pretty-print your fixed JSON and confirm the structure is intact.

Related Reading