Guides

How to Fix Common JSON Errors

5 min read

JSON is strict, and a single misplaced character can make an entire document invalid. The good news is that almost every JSON error comes from one of a handful of mistakes. Here is how to recognise and fix them.

Trailing commas

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

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

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

Single quotes instead of double quotes

JavaScript accepts single quotes, but JSON requires double quotes for both keys and string values.

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

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

Unquoted keys

Object keys must always be quoted strings. Bare identifiers are valid in JavaScript objects but not in JSON.

// Invalid
{ name: "Ada" }

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

Missing or mismatched brackets

Every { must have a matching } and every [ a matching ]. When JSON is deeply nested, it is easy to lose track. Beautifying the document with a formatter makes the indentation reveal where a bracket is missing.

Unescaped characters in strings

Double quotes, backslashes and newlines inside a string must be escaped with a backslash.

// Invalid
{ "path": "C:\Users" }   // single backslash

// Valid
{ "path": "C:\\Users" }  // escaped backslash

If you frequently need to embed JSON inside another string, the Stringify tool handles all of this escaping for you.

Frequently asked questions

Why does my JSON say "Unexpected token"?

This usually means a stray character — often a trailing comma, a single quote, or an unquoted key. Format your JSON to see the exact line where the parser gave up.

How do I validate JSON?

Paste it into a JSON formatter and validator. If the document is invalid, the tool reports the line and the reason; if it is valid, you get a clean, indented version back.

Try the tools