How the JSON Formatter Works

Back to the tool

The problem it solves

An API returns {"id":1,"name":"Alice","roles":["admin","editor"]} on one line. Your config file has a stray comma on line 47 and the parser gives you "SyntaxError: Unexpected token" with no line number. You're trying to check whether a webhook payload matches what the documentation says it should.

This tool does three things: it validates your JSON and shows you exactly where it broke, it reformats it so you can read it, and it minifies it when you need the smallest possible version. Everything runs in this tab — nothing you paste leaves your browser.

Parsing: how the tool finds errors

The formatter calls the browser's built-in JSON.parse — the same parser your JavaScript runtime uses when it processes an API response. That matters for two reasons: it is native code so it is fast, and it is what every browser tests obsessively so it handles edge cases correctly.

When JSON.parse rejects your input, it throws a SyntaxError with a message and, in most browsers, an offset or position. The tool catches that error, extracts the position, maps it back to a line and column, and shows it in the status bar. "Unexpected token } at line 12 column 4" means you have one too many closing braces — or a missing comma before it — on that line. You can fix it instead of guessing.

Common errors and what they mean:

Reformatting: what the indent option controls

Once the input parses cleanly, the tool calls JSON.stringify with an indent argument. The four options are:

The output is always canonical JSON: whitespace normalized, all Unicode escape sequences left as-is, numbers serialized the same way every time. Key order inside objects is preserved exactly as it appears in your input — the formatter does not sort keys.

Minify: when you need the smallest version

Minify mode (indent = 0) removes every space, newline, and tab that isn't inside a string value. A 40-line pretty-printed config becomes a single line. This is what you want before embedding JSON in a URL, a query string, an HTTP header, or a command-line argument where whitespace causes parsing problems.

Whitespace inside string values is never touched — if your JSON contains a string with spaces, those spaces survive minification.

Why in-browser parsing matters for JSON

JSON data often contains things you'd rather not hand to an unknown server: API keys buried in a config file, customer records from a database export, auth tokens from a session dump. A formatter that uploads your input — even temporarily, even to discard it immediately — is a privacy risk you cannot verify.

This tool has no server endpoint. After the page loads, the network is quiet: the only traffic is an anonymous Cloudflare Web Analytics beacon that carries no input data. The formatter keeps working after you go offline.

What the tool doesn't do

Standard JSON has no comment syntax. If your file uses // or /* */ comments (JSONC, used by VS Code config files) or allows trailing commas and unquoted keys (JSON5), you'll need to strip those before pasting here. JSON.parse will reject any of them with an "Unexpected token" error.

The formatter also doesn't sort keys, diff two documents, or query with JSONPath. One job, done well.