8 min read
Common JSON syntax errors
Trailing commas, bad quotes, comments, unclosed brackets, and undefined values are the JSON mistakes developers hit most often.
Table of contents
Trailing commas
Trailing commas are probably the most common JSON error. They happen when the final property or array item ends with a comma. JavaScript allows trailing commas in many contexts, but JSON does not.
Fixing this is simple: remove the comma after the last item. If the same data came from a JavaScript object, check for other JavaScript-only syntax too.
Quotes and object keys
JSON requires double quotes around string values and object keys. Single quotes, smart quotes, and unquoted keys are invalid. This often appears when copying from JavaScript examples or rich text documents.
Replace single quotes with double quotes and make sure every key is quoted. Be careful with automated replacements if string values contain apostrophes.
Brackets and escaping
Unclosed objects, unclosed arrays, and broken escape sequences can be harder to spot in dense JSON. Formatting helps only after the document is valid, so use a validator first. Parser positions often point near the issue.
Inside strings, backslashes must form valid escape sequences. File paths, regular expression-like text, and copied command strings are common sources of escaping mistakes.
Related guides
What is JSON and why developers use it
A practical explanation of JSON, where it appears in development, and why its simple structure made it the common language of APIs.
How to format JSON online
Learn when to format JSON, how online formatters work, and what to check when formatting fails.
How to validate JSON and fix common errors
A practical guide to JSON validation, parser messages, and the most common syntax mistakes developers run into.
FAQ
Why does JSON reject single quotes?
The JSON specification requires double quotes for strings and keys.
Are trailing commas valid JSON?
No. Remove commas after the final array item or object property.
Can JSON include comments?
No. Comments are not part of standard JSON syntax.
What is the fastest way to find an error?
Use a JSON validator, fix the first reported issue, and validate again.
Comments and invalid values
Standard JSON does not allow comments. It also does not allow undefined, NaN, Infinity, functions, dates, or regular expressions as native values. Use null or strings when a value needs to be represented in JSON.
If you need comments in a config file, consider whether the file is actually JSONC, YAML, or another format rather than JSON.