JSON Formatter — Pretty-Print and Validate

Pretty-print, minify, and find the error with a line number.

At a glance

InputJSON, pasted or typed
OutputThe same JSON, indented — or collapsed onto one line
Indent2, 4 or a tab character
On bad inputIt says where the error is rather than only that there is one
Where it runsEntirely in your browser — no file is uploaded to a server
PriceFree, with no account and no sign-up
OfflineWorks with no connection after the first visit

Reading the error

A parser fails at the first thing it cannot make sense of, which is often just after the real mistake. "Unexpected token }" usually means a trailing comma on the line above; "Unexpected end of JSON input" means a bracket was never closed.

The three that account for most invalid JSON: a trailing comma after the last item, single quotes instead of double, and unquoted keys. All three are legal JavaScript and none is legal JSON — which is why pasting an object straight out of code so often fails.

Comments, and why there are none

JSON has no comment syntax. Configuration files that appear to allow them — tsconfig.json, VS Code settings — are JSONC, a superset their own tools understand and a strict parser does not.

If you need a note inside real JSON, a key such as "_comment" is the usual workaround. It is ugly and it validates.

Minifying

Removing whitespace typically takes 15–30% off a payload, and gzip on the wire recovers most of that anyway — so minified JSON matters far more for a file shipped uncompressed or embedded in a page than for an API response.

Formatting and minifying are lossless in both directions: the values are untouched, only the whitespace between them changes. Key order is preserved as written, since JSON objects are not ordered by definition but every parser in practice keeps it.

Frequently asked questions

Why is my JSON invalid when it looks fine?

Usually a trailing comma, single quotes, or unquoted keys. All three are valid JavaScript and none is valid JSON, which is why code pasted straight from an editor often fails.

Can JSON have comments?

No. Files like tsconfig.json use JSONC, a superset understood only by their own tooling. For real JSON, a "_comment" key is the usual workaround.

Is my data sent anywhere?

No. It is parsed in your browser, which matters when the thing you are debugging is an API response with customer records in it.

Does formatting change my data?

No — only whitespace. Values, types and key order come through exactly as they went in, and minifying reverses it.

Something wrong with this tool, or an idea for it? Tell us