tallge

Tools / JSON formatter

JSON formatter and validator

Paste JSON, then format, minify or only validate it. The parser here is strict RFC 8259: no comments, no trailing commas, no single quotes.

Examples:

How it works

A small parser walks the input character by character, so an error can point at the exact line and column, and the cursor jumps there. Once the input is valid, JSON.stringify writes the output with the indent you picked. Sorting is recursive and orders keys by UTF-16 code unit, the same order as Array.prototype.sort. Array order never changes. One exception comes from JavaScript itself: keys that look like array indices, such as "2" and "10", are always printed first and in numeric order, sorted or not.

Pitfalls

JavaScript numbers are IEEE 754 doubles. Any integer larger than 2^53 (9007199254740992) may be rounded when parsed, and this tool parses before it prints. 9007199254740993 comes out as 9007199254740992. Database ids and 64-bit counters hit this most often. The tool warns when it happens; the fix belongs in the producer, which should send such values as strings.

Duplicate keys are legal JSON but undefined in meaning. Most parsers keep the last value, and so does this one, but the warning names the first duplicate so you can decide.

A leading byte order mark is skipped. Comments are rejected because JSON has none. Tolerant formats exist, but a config file that only one tolerant reader accepts tends to break the next tool in the chain.