JSON Formatter Online Free
Paste any JSON. Format it, minify it, validate it. Results appear instantly in your browser with no data sent anywhere.
A JSON formatter with its own hand-rolled syntax highlighter and a repair pass for the mistakes people actually make
Formatting valid JSON is one line: JSON.stringify(parsed, null, indent). This tool does that, but it also has to color every token for the highlighted view, render a collapsible tree, count keys and nesting depth, and attempt repairs on JSON that almost, but does not quite, parse. Each of those is a distinct piece of logic worth understanding.
Everything runs in your browser. There is no network call anywhere in the script, so pasted JSON, however sensitive, never leaves the page.
The highlighter is a hand-written character scanner
Rather than using a regex to color tokens after the fact, the highlighter walks the already formatted JSON string character by character and classifies each token as it goes: strings, then a lookahead check for a following colon to decide if a string is an object key or a value, booleans and null matched against fixed length substrings, numbers matched by scanning digits, a decimal point, sign, and exponent marker, and finally structural punctuation.
false, true, and null before falling through to number detection.
. e E + - until it hits something that does not belong, correctly handling scientific notation like 1.5e-10.
Three views, one parsed object
Formatting only calls JSON.parse once. The resulting object is kept in memory and reused across all three output modes, so switching views does not reparse anything.
| View | How it is built |
|---|---|
| Highlighted text | The character-scanning highlighter described above, output as spans inside a read-only block |
| Plain text | Direct JSON.stringify output in an editable textarea for copy or further edits |
| Collapsible tree | A recursive DOM builder that creates one row per key, with a toggle arrow for objects and arrays that hides or shows their children div on click |
The repair pass, and what it honestly cannot fix
Clicking repair first tries a plain JSON.parse. If that succeeds, nothing else happens. If it fails, four regex passes run in sequence: trailing commas before a closing bracket are removed, single quotes are swapped for double quotes, unquoted object keys matching an identifier pattern get quotes added, and both line and block JavaScript-style comments are stripped.
Extra actions beyond formatting
Minify
Runs the same parse and re-stringifies with no whitespace argument, producing a single-line output and updating the stats to reflect a one-line, minimum-byte result.
Sort keys
Recursively rebuilds every object with its own keys alphabetized through Object.keys(obj).sort(), while leaving array element order untouched, since arrays are ordered by position, not by key.
The stats row reports total object keys, total arrays, maximum nesting depth, and byte size, all computed by one recursive walk that tracks the deepest depth reached and increments counters for every key or array it passes through.
JSON specifications and tooling
- json.org is the canonical grammar diagram for JSON, useful for seeing exactly what counts as a valid number, string, or structural token.
- RFC 8259 is the current IETF standard defining the JSON data interchange format.
- MDN, JSON.stringify documents the indent argument this tool uses for pretty-printing.
- JSON5 is a real extended grammar supporting comments, trailing commas, and unquoted keys natively, worth reaching for if you need to parse this kind of relaxed JSON regularly rather than repair it after the fact.
Everyday JSON tasks
Pretty printing an API response copied from browser devtools, cleaning up minified config files before editing them, fixing JSON that was hand typed with single quotes or trailing commas, comparing structure with the tree view before writing a schema, and checking payload size before committing to a request body limit.
Questions About Json Formatter Online Free
Yes. It is completely free with no signup, no trial and no credit card required.
No. All processing happens in your browser. Nothing is sent to any server.
The tool highlights the error and shows the line and character position where the problem occurred.
Format adds indentation and line breaks to make JSON readable. Minify removes all whitespace to reduce file size for production use.
Yes. There is no size limit. Very large inputs may slow the browser slightly but will still process correctly.
From the blog
Deep dives on the things these tools touch
Minification, UUID collisions, diffing API responses, and the other questions that come up around this toolset.