How to Validate and Format JSON (and Fix the Most Common Errors)
XUtilHub Team ·
JSON is strict. A single misplaced comma can break an API request or a config file, and the error messages from most parsers aren't very helpful. This guide covers the mistakes we see most often and how to fix them quickly.
The 6 most common JSON errors
1. Trailing commas
{ "name": "Ada", "age": 36, }
JavaScript allows a comma after the last item, but JSON does not. Remove the final comma.
2. Single quotes
{ 'name': 'Ada' }
JSON strings and keys must use double quotes.
3. Unquoted keys
{ name: "Ada" }
Every key must be a double-quoted string: "name".
4. Comments
JSON has no comments. Neither // nor /* */ is allowed. If you need comments in config files, consider JSONC, YAML or TOML instead.
5. Special values
undefined, NaN, Infinity and functions are not valid JSON values. The only literals allowed are true, false and null, which must be lowercase.
6. Unescaped characters in strings
Line breaks, tabs and double quotes inside a string must be escaped: \n, \t, \".
How to validate JSON
Paste your JSON into the JSON Validator. It tells you instantly whether the JSON is valid and, if not, shows the line and column of the first error.
How to format (pretty-print) JSON
Minified JSON is hard to read. The JSON Formatter re-indents it with 2 or 4 spaces or tabs, so its structure is clear at a glance. To go the other way, for a production payload, use the JSON Minifier.
How to repair broken JSON automatically
If you're dealing with JSON copied from JavaScript code, logs or an LLM response, the JSON Fixer can repair most problems automatically. It adds missing quotes, removes trailing commas and comments, converts single quotes, and closes unbalanced brackets.
Quick checklist
- Use double quotes for keys and strings
- Don't leave a comma after the last item
- Don't include comments
- Write
true,falseandnullin lowercase - Escape special characters inside strings
Tools mentioned in this article
JSON Formatter
Format and beautify JSON online. Pretty-print with 2 or 4 space indentation, validate syntax and copy or download the result. Free and private.
JSON Validator
Validate JSON online and find syntax errors instantly, with line and column numbers. Free JSON lint tool that formats valid JSON too.
JSON Fixer
Fix invalid JSON automatically: missing quotes, trailing commas, single quotes, comments, unclosed brackets and more.