How to Format and Validate JSON
JSON is strict. One stray comma or one smart quote and a file that looks fine will be rejected outright. Validating first is faster than guessing, and formatting makes real problems visible.
The Rules JSON Actually Enforces
- Objects and arrays are wrapped in
{}and[]. - Keys are always in double quotes. Single quotes are invalid.
- Strings use double quotes, and a literal quote inside must be escaped as
\". - No trailing commas after the last item in an object or array.
- Only
true,falseandnullare allowed as bare values. - No comments. JSON does not support them.
Our JSON Formatter checks all of these and reports the exact position of the first failure.
The Five Errors That Cause Most Failures
1. Trailing commas
A comma after the final key or array element is the most common mistake by a distance. {"a":1,} is invalid; it must be {"a":1}.
2. Single quotes instead of double quotes
Python, PHP and JavaScript object literals all accept single quotes, so code copied out of a script often fails as JSON. Search and replace every ' that delimits a key.
3. Smart quotes pasted from a document
Text copied from Word, Google Docs or a messaging app often contains typographic quotes. They look identical to real quotes but are different characters, and no parser accepts them.
4. Unescaped newlines and backslashes
A string cannot contain a raw line break. Use \n for a newline and \\ for a literal backslash, such as in Windows file paths.
5. Comments
Many config files allow comments and JSON does not. Remove every // and /* */ before validating.
Minify or Pretty-Print?
Pretty-printing adds indentation and line breaks, which makes a file readable to a person and usually larger on disk. Minifying strips all of that, which makes it smaller and often faster to load. Use pretty format while you are editing, and minify before shipping JSON to a browser.
The same tool handles both directions: format a minified file to inspect it, then minify it again before use.
Reading an Error Message
Most parsers report a position, not a cause. A pointer at line 3, column 24 usually means look at the character just before that point, which is very often the unexpected comma or the missing closing bracket. Validating after every small edit turns a long debugging session into an immediate, precise error.
Frequently Asked Questions
Related Tools
Shop for calculators and productivity tools on Amazon — great deals for every need.
Shop on Amazon →