Toolium

JSON Formatter

Validate, format, and minify your JSON data

100% client-sideFree, no signup

What formatting does under the hood

When I built this formatter I assumed the hard part would be the indentation logic. It was not. The hard part is what happens when the input is not the clean JSON you thought it was, so this guide covers both halves: the mechanics and the places where your data will fight you.

Parse first, print second

The tool does not shuffle whitespace around with string tricks. It hands your input to the browser's built-in JSON.parse, which builds a real data structure in memory, then re-serializes it at the indentation you pick, two spaces, four spaces, or a tab, with a line break between every key. Minify runs the same parse and serializes with no whitespace at all, which is the form you want for API payloads and config files where bytes matter.

Parsing first has a useful side effect. Invalid JSON never reaches the printing step. JSON.parse throws a SyntaxError, and the tool shows it, including the character position where the parser gave up, so you fix the spot rather than the whole file. Both directions are lossless: a formatted document and its minified twin differ only in whitespace, so you can round-trip without breaking a strict schema.

Where it breaks, and why that is on purpose

The parser is strict JSON per the specification, not the relaxed dialect your editor tolerates. Strictness is a feature here. A permissive parser would format broken input without complaint, and the error would surface later in production where it costs more. These inputs fail, or worse, pass while changing your data:

  • Trailing commas. Fine in JavaScript object literals, rejected by JSON. This is the single most common error the tool catches.
  • Single quotes. JSON strings and keys require double quotes. Anything copied out of Python or a JS console tends to arrive with single quotes.
  • Comments. No line comments, no block comments. JSONC and JSON5 allow them; this parser does not.
  • Big integers. JavaScript represents integers exactly only up to 2^53 minus 1. A longer numeric ID parses without any error and comes back rounded.
  • Duplicate keys. The spec leaves this undefined, and JSON.parse keeps the last value it sees. The earlier value vanishes silently.
  • A stray BOM. Some Windows editors prepend an invisible byte-order mark. The document looks perfect and fails on character one.

Two things people hit

Why does a 50 MB file freeze the tab?
Parsing builds the whole structure in memory, and rendering one enormous indented string is expensive in a browser. Files under 10 MB behave fine, sluggishness sets in past that, and around 50 MB the tab can hang or crash. For files that size, jq on the command line handles them without breaking a sweat.
Can I change the indentation, or get JSON5 support?
The indent dropdown offers two spaces, four spaces, or a tab. JSON5 and JSONC stay off the table on purpose: a permissive mode would format inputs that standard parsers downstream reject, and hiding that failure defeats the point of validating here.