JSON Formatter Online Free

💻 Developer Tools Free Forever

JSON Formatter Online Free

Paste any JSON. Format it, minify it, validate it. Results appear instantly in your browser with no data sent anywhere.

Indent
Input JSON
Parse error
Output
About This Tool

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.

Step 1 String with key detection When a quoted string ends, the scanner peeks forward past any whitespace to see if the next non-whitespace character is a colon. If so, the string is rendered as a key rather than a value, which is how key and value strings get different colors without a full parse tree.
Step 2 Literal keywords The scanner slices five and four character substrings ahead of the cursor and compares them directly against false, true, and null before falling through to number detection.
Step 3 Numbers A leading minus sign followed by a digit, or a digit alone, starts a number scan that consumes digits plus the characters . e E + - until it hits something that does not belong, correctly handling scientific notation like 1.5e-10.
// simplified from the actual highlighter, key vs value string detection var j = i; // after closing quote while (j < len && ‘ \n\r\t’.indexOf(json[j]) >= 0) j++; if (json[j] === ‘:’) { res += ‘<span class=”key”>’ + str + ‘</span>’; } else { res += ‘<span class=”value”>’ + str + ‘</span>’; }

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.

ViewHow it is built
Highlighted textThe character-scanning highlighter described above, output as spans inside a read-only block
Plain textDirect JSON.stringify output in an editable textarea for copy or further edits
Collapsible treeA 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.

The repair function is a set of common-case regex fixes, not a real JSON5 or JSONC parser. It handles the four mistakes people make most often when copying JSON out of a JavaScript file or a log statement: trailing commas, single quotes, unquoted keys, and stray comments. It cannot fix missing brackets, missing colons, or genuinely broken structure, and the tool says so directly in its error message rather than pretending the fix always works.

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.

Hand-rolled highlighter Collapsible tree view Regex-based repair Recursive key sort

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.

Common Questions

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.

Privacy Overview

Cookies let this site remember your preferences and show us which tools people actually use. Full detail sits in our Privacy Policy.