JSON Formatter

Pretty-print JSON and get a precise line and column when it is invalid, rather than a vague complaint.

Processed on your device — no upload

termiva json --pretty
0 chars
0 chars
valid lines nothing uploaded

How to use it

  1. Paste the JSON, or choose a file.
  2. Choose an indent, and sort the keys if that helps you read it.
  3. Copy the formatted result.

How it works

Formatting is a parse followed by a re-serialisation. That is the important property: if the output appears, the input was valid JSON, because invalid JSON never gets as far as being printed. Validation is not a separate step you can forget.

The error messages are the reason to use this rather than a text editor. A browser reports a syntax problem as a character offset — “position 4,182” — which is unusable on a large file. That offset is converted here into a line and column, with the offending line quoted, so the fix takes seconds rather than a hunt.

Sorting keys alphabetically is there for comparison. Two API responses containing the same data in a different key order look completely different in a diff; sort both and the real differences are all that remain.

Everything runs in your browser. Pasting an API response into a formatter is one of the most common ways credentials leak — payloads routinely contain tokens, and the usual online formatter sends what you paste to a server.

A worked example

An API returns one long line of JSON and something in it is wrong. Press Load a sample to see the formatted shape of a typical order payload.

Now break it deliberately: delete a closing brace and look at the message. Instead of “Unexpected end of JSON input” you get the line and column, and the line itself quoted back. On a 4,000-line file that is the difference between a fix and an afternoon.

The most common real errors, in order: a trailing comma after the last item in an array or object; single quotes instead of double quotes; and an unescaped newline inside a string. All three are legal in JavaScript and none is legal in JSON, which is why they survive review and fail at parse time.

The sorting option earns its place when comparing two versions of a config file. Sort both, then put them through the text comparison tool — what remains is the actual change rather than a hundred lines of reordering.

To go the other way and strip the whitespace out again, the minifier shows how many bytes the formatting was costing.

Questions

Does this beautify and validate JSON?

Both. Formatting it pretty print style with real indentation is also the fastest way to validate it: if the structure is wrong the tool stops and names the line.

How do I find a parse error?

The message gives a line and a column and quotes the offending text, rather than the raw character offset a browser reports. That is usually enough to lint the problem by eye.

Is my JSON uploaded?

No. It is parsed in your browser. This matters: API payloads frequently contain tokens and personal data, and most online formatters send what you paste to a server.

How do I find the error in a large file?

The message gives a line and column and quotes the offending line, rather than the raw character offset a browser reports.

What are the most common JSON errors?

A trailing comma after the last item, single quotes instead of double quotes, and an unescaped newline inside a string. All three are valid JavaScript and invalid JSON.

Does formatting change my data?

No. Only whitespace changes — and key order if you ask for sorting. The values are untouched.

Why would I sort the keys?

To compare two files. Identical data in a different key order produces a diff full of noise; sorting both leaves only the real differences.

Does it support JSON with comments?

No. Comments are not part of JSON, so a file containing them will not parse. Strip them first if you are working with a config format that allows them.

Two spaces or four?

Two is the most common convention and produces a smaller file. Four is easier to follow when nesting runs deep. Neither affects the data.

Is there a size limit?

No fixed limit. Formatting is fast, though a file of several megabytes will make the text box itself sluggish to scroll.