Boneyard Tools

Common JSON errors and how to fix them

Trailing commas, single quotes, unquoted keys and other JSON mistakes, with quick fixes and how to read the error hint.

Trailing commas

JSON does not allow a comma after the last item in an object or array, even though JavaScript happily accepts one. A stray comma before a closing brace or bracket is one of the most common reasons a paste fails to parse. Delete the trailing comma and the structure becomes valid. This trips people up constantly because most code editors and linters permit trailing commas in source code, so the habit carries over into hand-edited JSON.

Single quotes and unquoted keys

In JSON every string, including every object key, must be wrapped in double quotes. Single quotes and bare keys are legal in JavaScript object literals but not in JSON, so a snippet copied from code often needs quoting fixed. Replace single quotes with double quotes and wrap any bare key such as name in double quotes to make it name in quotes. If you find yourself doing this by hand a lot, it usually means you are pasting a JavaScript object rather than true JSON.

Reading the line and column hint

When JSON is invalid, the formatter shows the parser message along with a line and column when it can work one out. That location marks where parsing gave up, which is often just after the real mistake rather than exactly on it. If the caret points at a closing brace, the actual problem is frequently a missing comma or an unclosed string a little earlier. Scan backward from the hint to find the first token that looks out of place.

Unescaped characters and duplicate keys

Strings cannot contain a raw double quote, backslash or literal newline; those must be escaped, so a Windows path or a quotation inside a value needs backslashes. Another quiet pitfall is duplicate keys: JSON technically allows them but parsers keep only the last one, so data silently disappears without an error. If a field seems to lose its value after formatting, check whether the same key appears twice in the object.

Frequently asked questions

Why does my error point at the closing brace?

The parser reports where it could no longer continue, which is usually just past the real mistake. Look at the tokens immediately before the hint, especially a missing comma or an unterminated string.

How do I include a quote inside a JSON string?

Escape it with a backslash, so a quote becomes backslash then quote. The same applies to a literal backslash and to newlines, which use the escape sequences the JSON spec defines.