💻 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 goes further. It uses its own strict parser, so large numbers like 12345678901234567890, values like 1.50 and duplicate keys come out exactly as you wrote them, which JSON.stringify cannot promise. 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 parses the input once. The resulting tree 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 textThe formatted text in a plain textarea, easy to select and copy
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 strict parse. If that succeeds, nothing else happens. If it fails, a lenient tokenizer reads the input the way a JavaScript engine would and writes it back as strict JSON: comments are dropped, single-quoted strings become double-quoted, unquoted keys get quotes, trailing commas go, missing commas between items are added, Python style True, False and None become true, false and null, and brackets left open at the end are closed. Because it works token by token, an apostrophe inside a string or a URL like http://example.com is never damaged.

The repair pass covers the common mistakes, not every possible one. It handles what people hit most when copying JSON out of a JavaScript file, a Python print or a log line. It cannot guess a missing colon, a bracket missing in the middle, 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 Token-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 the JSON Formatter

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 explains what went wrong, shows the line and column, highlights the exact character and selects it in the input. Fix Common Errors can repair many typical mistakes for you.

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. A 5 MB file formats in a few seconds. For very large output the highlighted view switches to plain text and the tree view loads branches as you open them, so the page stays responsive.