Common JSON Syntax Errors and How to Fix Them

Published 2026-04-12 · 8 min read

JSON is famously strict. The grammar is small, which makes it easy to parse, but it also means the parser will reject your file the moment a single character is out of place. If you've ever stared at a cryptic Unexpected token message, this guide is for you. Here are the eight most common JSON syntax errors, why they happen, and how to fix each one.

1. Trailing commas

JavaScript allows trailing commas in arrays and objects. JSON does not. The very last element cannot be followed by a comma.

// ❌ Invalid
{ "a": 1, "b": 2, }

// ✅ Valid
{ "a": 1, "b": 2 }

This one bites developers who hand-edit JSON — you delete the last field and forget to delete its trailing comma. The validator will point you straight at the offending character.

2. Single quotes instead of double

JSON strings must use double quotes. Single quotes are a Python and JavaScript habit that the JSON spec forbids.

// ❌ Invalid
{ 'name': 'Ada' }

// ✅ Valid
{ "name": "Ada" }

3. Unquoted keys

Object keys must be strings, and strings must be double-quoted. JavaScript lets you write { name: "Ada" }, but that is not JSON.

// ❌ Invalid
{ name: "Ada" }

// ✅ Valid
{ "name": "Ada" }

4. Comments

JSON has no comment syntax. Neither // nor /* ... */ is allowed. If you need comments in your configuration, consider YAML or a superset like JSON5 or HJSON, then convert to JSON before runtime.

5. Missing commas between elements

Every element in an array or object must be separated from the next by a comma. Copy-pasting from a stringified log often drops commas across line breaks.

// ❌ Invalid
{
  "a": 1
  "b": 2
}

6. Unmatched braces and brackets

Every { needs a closing }, every [ a closing ]. When you're editing nested structures by hand it's easy to delete one side of a pair without the other. The formatter helps here because malformed JSON fails to parse and highlights exactly where the structure broke.

7. Numbers with leading zeros or trailing dots

JSON numbers follow a strict grammar: no leading zeros (except for 0 itself), no trailing decimal point, no hex or octal.

// ❌ Invalid
{ "count": 007 }
{ "price": 9. }
{ "hex": 0xff }

// ✅ Valid
{ "count": 7 }
{ "price": 9.0 }
{ "hex": 255 }

8. undefined or NaN

JSON has null but not undefined. It also has no way to represent NaN or Infinity. Any of those will crash a strict parser.

// ❌ Invalid
{ "value": undefined }
{ "rate": NaN }

// ✅ Valid
{ "value": null }
{ "rate": 0 }

Finding the error fast

The biggest time sink isn't fixing a syntax error — it's finding it. Error messages fromJSON.parse mention a position, but humans don't naturally count characters. JSON Mint's validator translates the position into a line and column and highlights the line, so you can jump straight to the problem and fix it. Paste your broken JSON, read the error, fix the character, and move on.

More from the blog