Input
{"name":"Ada","roles":["admin","editor"]}Formatted result
{
"name": "Ada",
"roles": [
"admin",
"editor"
]
}The tool can show where JSON is invalid, but you must decide whether a value is text, a number, or null.
A JSON Formatter takes compact or messy JSON and rewrites it with consistent indentation so you can actually read the structure — then, one click later, minifies it back down for production. It also validates as it goes: instead of a vague “unexpected token” from an application log, you see the exact line and column where the document breaks. Developers use it to inspect API responses, debug webhooks, review configuration files, and prepare payloads before sending them.
.json file.Example 1 — reading an API response. A fetch call returns one long line:
{"user":{"id":42,"name":"Ada","roles":["admin","editor"],"lastLogin":"2026-09-01T09:14:00Z"},"active":true}
Formatting expands it so the hierarchy is obvious: a top-level object with user and active, and inside user a four-key object with a roles array. In the indented form you can see at a glance that roles is an array, not a string — a distinction that is nearly invisible in the one-line version.
Example 2 — the trailing comma. A config edited by hand:
{
"timeout": 30,
"retries": 3,
}
Validation reports the error at the comma before the closing brace. Remove it and the document is valid. This is the single most common real-world JSON mistake, largely because JavaScript and Python both allow trailing commas.
Example 3 — shrinking a payload. Before shipping a config file or embedding JSON in a log line, minify turns a 40-line pretty-printed object into one compact line, often cutting 30–50% of the bytes with zero data loss.
JSON has a strict, small grammar: values are objects ({}), arrays ([]), strings (double quotes only), numbers, true, false, and null. A parser reads the text left to right and builds a tree in memory; every token must fit the grammar or parsing stops at that character.
Formatting walks that tree and re-serializes it with an indent step (commonly two or four spaces) and a newline after each property or element. Minifying does the same walk but emits no optional whitespace at all. Because both operations re-serialize a parsed structure, they cannot silently change values — but they also cannot “fix” malformed input, which is why the validator reports rather than repairs.
One consequence worth remembering: since keys are stored in an object, duplicate keys collapse during parsing, and the last occurrence wins. That is standard behavior, not a bug, but it means a document with repeated keys will look different after a round trip.
JSON itself does not care about indentation, so teams pick a convention and stick to it. Two spaces per level is the most common default in JavaScript and web tooling; four spaces appears often in Java and Python ecosystems. Some teams also sort object keys alphabetically to make diffs stable — when a new key is added, only its line changes instead of the whole block shifting. If your project uses a formatter such as Prettier or an ESLint rule, run it on JSON files too so that a pull request shows real data changes rather than whitespace churn. The formatter here follows the same idea manually: apply it, copy the result, and keep the repository consistent.
{name: 'Ada'} is valid JavaScript but invalid JSON; both need double quotes.// and /* */ are not part of JSON. Use a .jsonc-aware editor for configs that need them.EF BB BF at the start of the file, which strict parsers reject at position zero. Re-save as UTF-8 without BOM."id": "007" stays a string after formatting; if a downstream system expects a number, the quote matters.No. Both operations only add or remove whitespace — indentation, line breaks, and spaces between tokens. The values themselves, including number precision and string contents, are preserved byte for byte after re-parsing. Only invalid JSON is rejected.
The parser stopped at the first character it could not interpret. The most common causes are a trailing comma before a closing brace or bracket, single-quoted keys or strings, comments, or an unquoted key. Paste the text into the formatter and it marks the exact line and column.
It detects and reports errors rather than guessing fixes, because silently altering a document can change its meaning. For common cases such as a trailing comma or a missing quote, the error message points at the exact spot so the fix takes seconds. For structural repairs, edit the source rather than trusting an auto-correction.
Formatting and minifying run entirely in the browser, so the practical limit is your device's memory. Files of a few megabytes format instantly; beyond roughly 10–20 MB the browser may pause while rendering the indented output. For huge datasets, minify to inspect or split the file first.
No. Parsing, validation, formatting, and minifying all happen locally with JavaScript in your own browser. Nothing is transmitted or logged, so the tool is safe for confidential API payloads, tokens, and internal configuration.
Formatting (beautifying) expands the document with indentation and line breaks so a human can read the structure. Minifying does the opposite: it removes every optional space and line break to produce the smallest possible payload for production, storage, or network transfer. The data is identical either way.
Reviewed by the HandyTools Hub team · Last updated