JSON Formatter

Format, validate, and minify JSON instantly. Errors highlighted with line and column.

Enter input above to see the result.

Why JSON breaks

JSON travels minified — every byte counts when an API response is being shipped. But minified JSON is unreadable, and hand-edited JSON is almost always invalid on the first try. This tool round-trips through the browser's native JSON.parse / JSON.stringify to produce indented, copy-able output, validate the structure, or strip whitespace back out. Nothing is uploaded; everything happens in the page.

The five syntax errors that catch everyone

Format, validate, or minify — which button to reach for

Integer precision and the silent round-trip bug

JavaScript's JSON.parse converts every number to a 64-bit float. Numbers larger than 253−1 (9,007,199,254,740,991) lose precision silently — common with database IDs, Snowflake IDs, and timestamp-in-nanoseconds values. If your wire protocol uses 64-bit integers, transport them as strings. There's no warning when this fails; you just get the wrong number back.

JSON's lookalikes: JSONC, JSON5, NDJSON

Three dialects look identical but fail strict validation: JSONC (JSON with comments — VS Code config files, tsconfig.json), JSON5 (relaxed syntax with trailing commas, single quotes, unquoted keys, comments — common in tooling configs), and NDJSON / JSONL (one JSON object per line with no surrounding array — common in log pipelines and streaming exports). If your input fails to parse and looks mostly-valid, check which dialect you actually have.

Indentation, file size, and diff hygiene

Trailing comma, line 1, col 57

Paste the minified line {"user":{"id":42,"roles":["admin","editor"],"active":true}} and hit Format: it re-emits the same object indented two spaces across seven lines, and the meta line reports the character and line count. Hit Minify and it round-trips straight back to the 58-character original. Now add a trailing comma — …"active":true,} — and Validate fails with ✗ Unexpected token } … line 1, col 57: the tool takes the parser's raw character position and converts it to a line and column for you.

Questions people actually ask

Why does every error say "line 1"? Because minified JSON is one line — the line/column is computed from the character offset, so a single-line document puts everything on line 1. Format the JSON first, then re-validate, and the reported line will actually point at the offending row.

Format (2) or Format (4) — does it matter? Only for size and house style; both are valid JSON. Four-space indent is easier to scan but noticeably larger — a 50 KB payload is roughly 80 KB at four-space and 30 KB minified. Pick one indent and stay consistent so diffs stay clean.

Can minifying change my numbers? Yes, silently. The round-trip goes through JSON.parse, which stores every number as a 64-bit float, so an integer above 9,007,199,254,740,991 (2⁵³−1) — a Twitter/Snowflake ID, a nanosecond timestamp — comes back subtly wrong. Transport those as quoted strings.

My JSON looks fine but won't parse. It's almost always one of four things: single quotes instead of double, a trailing comma, // or /* */ comments (that's JSONC, not JSON), or smart quotes pasted in from a word processor. None are legal JSON.

Parse tree in, whitespace out

Formatting parses the text into a real data tree and re-serialises it with consistent indentation — which is why a formatter that rejects your input has just found a genuine syntax error, not been fussy. JSON's grammar is deliberately tiny: double-quoted keys, no trailing commas, no comments, and only four scalar types. Pretty-printing walks the parsed tree and adds two-space (or four-space) indentation per nesting level; minifying does the reverse, stripping all insignificant whitespace. Because both go through a real parse, the output is guaranteed well-formed even when the input's spacing was chaotic — the round-trip is the validation.

The upstream-token trap

The errors that break JSON are almost always the four things JSON forbids that other formats allow: a trailing comma after the last array or object element, single quotes instead of double, unquoted keys, and JavaScript-style // comments. All are legal in a JS object literal and all are invalid JSON. When a parser points at a line, look one token before it — the real fault is usually the character just upstream of where it gave up.

Related

Decode the messages parsers give you: reading JSON error messages.