Home/Blog/How to Fix Invalid JSON
JSON · Debug

How to Fix Invalid JSON

4 min readUpdated April 2026Developer Tools
Got a 'SyntaxError: Unexpected token' or 'JSON Parse error'? This guide covers every common JSON error, what causes it, and exactly how to fix it.

JSON Formatter & Validator

Paste your broken JSON — errors are highlighted with the exact line number. Free and instant.

Open JSON Formatter & Validator →

Find JSON errors instantly

Before manually hunting through your JSON, paste it into the JSON validator on tinybench.dev. It highlights the exact line and position of every syntax error — saving you from scrolling through hundreds of lines looking for a missing comma.

Error: Trailing comma

The most common JSON error. JSON does not allow a comma after the last item in an object or array.

Invalid — trailing comma
{
  "name": "Ada",
  "age": 36,
}
Fixed
{
  "name": "Ada",
  "age": 36
}

Error: Unquoted keys

JavaScript allows unquoted object keys, but JSON requires all keys to be double-quoted strings.

Invalid — unquoted key
{ name: "Ada", age: 36 }
Fixed
{ "name": "Ada", "age": 36 }

Error: Single quotes

JSON strings must use double quotes. Single quotes are invalid.

Invalid — single quotes
{ 'name': 'Ada Lovelace' }
Fixed
{ "name": "Ada Lovelace" }

Error: Missing comma

Each property except the last must be followed by a comma.

Invalid — missing comma
{
  "name": "Ada"
  "age": 36
}
Fixed
{
  "name": "Ada",
  "age": 36
}

Error: Comments in JSON

JSON does not support comments. Neither // nor /* */ are valid.

Invalid — comment
{
  "debug": true  // remove this in production
}
Fixed — remove comments entirely
{
  "debug": true
}
Need comments in config files? Use JSON5, JSONC (VS Code's extended format), YAML, or TOML instead — these are supersets that allow comments. Standard JSON parsers can't read them.

Error: Unescaped special characters in strings

Quotes, backslashes, and control characters inside strings must be escaped.

Invalid — unescaped quote
{ "message": "He said "Hello" to her" }
Fixed — escaped quote
{ "message": "He said \"Hello\" to her" }
CharacterEscape sequence
Double quote\"
Backslash\\
Newline\n
Tab\t
Carriage return\r

Error: undefined, NaN, or Infinity

These JavaScript values are not valid JSON. Replace them with null or a number string.

Invalid
{ "value": undefined, "score": NaN, "max": Infinity }
Fixed
{ "value": null, "score": null, "max": 1e308 }

Frequently asked questions

Why does my JSON work in JavaScript but fail JSON.parse()?
JavaScript object literals are more permissive than JSON — they allow unquoted keys, trailing commas, single quotes, and comments. JSON.parse() is strict and follows the JSON specification (RFC 8259). Always use a JSON validator to check strict compatibility.
What does "Unexpected token at position N" mean?
The parser found a character it didn't expect at that position. Count N characters from the start of the string — the character there (or just before it) is where the error is. A JSON validator shows this visually.
Can I have an empty JSON object or array?
Yes. {} (empty object) and [] (empty array) are both valid JSON.

Try it free — no sign-up needed

Runs entirely in your browser. Nothing uploaded, nothing stored.

Open JSON Formatter & Validator →

Related tools on tinybench.dev