JSON Formatter & Validator

Format, minify, sort and validate JSON - with the line and column of the first error.

Output options
Start from a preset
JSON input

Output — formatted.json

About this tool

Paste JSON and get it formatted, minified or sorted, with a validation message that points at the line and column where parsing failed instead of a vague "unexpected token". The panel under the output reports key count, nesting depth and how much smaller the minified version is. Your JSON is parsed in this browser tab and never uploaded, so it is safe to paste an API response that contains real data.

What JSON does not allow

Almost every "invalid JSON" error is one of four things, and all four are legal in JavaScript, which is why they slip through: a trailing comma after the last item, single quotes instead of double quotes, an unquoted object key, or a // comment. JSON has none of them. It also has no undefined, no NaN, no Infinity and no leading + on a number.

The other classic is a duplicate key. JSON.parse does not complain - it silently keeps the last one - so a config file with two "port" keys quietly uses the second, and no validator will tell you. Search for the key by hand if a value is being ignored for no apparent reason.

Why the error message here is more useful

Browsers report a character offset ("position 47"), which is useless in a 4,000-character file. This tool converts that offset into a line and column and shows you the offending line, because the fix is almost always one character away from where parsing stopped - and usually on the line before it, since a missing comma is only noticed once the next token arrives.

Frequently asked questions

Is my JSON sent to a server?

No. The formatting and validation happen in JavaScript in this tab. There is no request behind the output box, which is the whole reason this tool is safe to use on an API response containing customer data or an access token.

What does sorting the keys do?

It reorders every object alphabetically, at every level of nesting. Key order carries no meaning in JSON, so this changes nothing about the data - but it makes two API responses that list their keys differently diffable in a text editor.

Why did minifying save less than I expected?

Because whitespace compresses extremely well. A pretty-printed file is often only a few percent larger than a minified one after gzip. Minify JSON for API payloads by all means, but if the goal is transfer size, enabling compression on the server matters far more.

Can it handle JSON Lines or JSONC?

No - it validates strict RFC 8259 JSON. JSON Lines is one object per line and needs parsing line by line; JSONC (JSON with comments, as in tsconfig.json) is not JSON at all, and comments will be reported as an error.