GUIDE深度 · Deep dive

Common JSON Syntax Errors

JSON is stricter than JavaScript object literals: keys need double quotes, trailing commas are not allowed and comments are invalid. Most parse errors come from one of these near the reported position.

更新 2026-10-31 · 公式可核验

The top five

Trailing comma: {"a":1,} is invalid.

Single quotes: {'a':1} is invalid.

Comments: // or /* */ are invalid.

Unescaped newlines/quotes inside strings; use \n and \".

BOM or invisible characters copied with the text.

How to debug

Look one or two lines around the reported position; use a formatter/validator to locate it.

Pasting into JSON.parse in the console shows the same error.

FAQ

Why does it work locally but fail online?

The online copy may use JSON5/comments or include a BOM.

Can I use YAML instead?

Yes, but APIs usually require JSON; YAML allows comments but is not JSON.

Sources

Related calculators

JSON FormatterPaste JSON to format, minify, validate and locate syntax errors.

More guides

Format vs Minify JSONRead guide