Skip to the tool

JSON formatter

MDV Tools

Paste JSON. Get it indented, minified, or with keys sorted. Malformed input is reported with the line and column that broke it.

Runs on this device Works offline
0 bytes
Result
paste json above
How this works

The text is first read by a scanner in this page that follows the JSON grammar of RFC 8259 one character at a time. It stops at the first error and prints the line, the column (counted in characters, a tab is one), what the grammar expected there and what it found, then the line itself, clipped to 30 characters either side, with a caret under the column. Only text the scanner accepts goes on to the browser's JSON.parse, and the parsed value is written back out with JSON.stringify(value, null, indent).

Sorting keys rebuilds every object with its keys in Array.prototype.sort order, which is code-unit order, so Z sorts before a. One exception, sorted or not: keys that are array indices, such as "0" or "42", are always written first in numeric order, because that is how JavaScript objects hold them. Duplicate keys collapse to the last one, per the parser, without a warning.

Every number is read as a 64-bit float, and the float is what gets written. 1.0 becomes 1 with nothing lost, but 12345678901234567890 becomes 12345678901234567000, 1e400 becomes null and -0 becomes 0. JSON text allows those numbers; the loss happens in the reading. When a number comes out with different digits, sign or magnitude than it went in (trailing zeros and exponent notation aside), the page counts them and names the first.

Input above 4,000,000 characters is refused rather than attempted. Valid JSON nested thousands of levels deep can run the browser out of stack while it is written back out; the page then says so instead of formatting it. The caret counts characters, so it can drift under wide characters such as CJK or emoji, or when a narrow screen wraps the line. Nothing is uploaded: there is no server in this file.

The Dark button remembers its setting in this browser's local storage. Nothing you type or drop into the page is stored.