JSON sort / minify / escape
Sort object keys, minify to one line, or escape/unescape JSON for embedding inside another string. Runs on your device.
Runs on your device. The file is never uploaded.
JSON sort / minify / escape offers four modes. Minify, the default, puts the whole document on one line. Sort puts object keys in alphabetical order at every depth, while escape and unescape move text in and out of a JSON string literal. Arrays are never reordered, since position carries meaning in JSON.
Questions
What are the four modes?
Minify, which is the default and prints the JSON on one line with no spaces; sort, which orders every object key alphabetically at every level and pretty-prints with 2 spaces; escape, which turns your text into a JSON string literal; and unescape, which does the reverse.
What does escape produce?
Your whole file wrapped in double quotes with the inner quotes, backslashes, newlines and control characters escaped, ready to paste as a string value inside another JSON document. Escape does not parse your input, so it works on any text, not only on valid JSON.
Why does unescape refuse my input?
Two reasons, each with its own message. If the text is not parseable at all you get "not a valid JSON string literal:" with the parser message. If it parses but is not a string, for example a bare number or an object, you get "input decodes to a non-string JSON value; unescape expects a quoted string". Unescape wants the quotes included.
Does sort reorder arrays too?
No. Only object keys are sorted, and it happens at every level of nesting. Array order carries meaning in JSON, so arrays are left exactly as they were and their contents are walked without being reordered. That is what makes sorting useful before a diff: keys line up, while the data itself is unchanged.
How is this different from the JSON format tool?
That one validates and pretty-prints with a choice of indentation. This one is for the other three jobs: making JSON as small as possible, sorting keys so two documents diff cleanly, and moving JSON in and out of a string. Sorting exists in both because it is useful next to either.
Is my JSON uploaded?
No. Every mode runs in a Web Worker in this tab, and nothing is transmitted or stored. That includes escape and unescape, which people often reach for when a token or a connection string has to be embedded in another document. The page keeps working with the network off.