Pretty Print JSON

Format JSON for readability


Description

Format JSON dictionaries to be easier to read. This shortcut uses JavaScript’s native JSON.stringify() function to convert dictionaries into legible plain text.

This shortcut can be run on its own, in which case it will prompt you to enter the JSON to pretty print, or it can be run from the share sheet for text or files containing JSON. It presents the beautified JSON in Quick Look and then asks whether you would like to copy the beautified JSON to the clipboard.

This was inspired by the “JSON Validator and Beautifier” Instant Answer developed by the DuckDuckHack community for DuckDuckGo.

Thank you to @gluebyte for providing valuable insight into the quirks of Shortcuts, particularly the nature of Get File Of Type and the way Shortcuts handles dictionaries!


Latest Release Notes

1.3 - May 26, 2020, 4:22 p.m.

Removes “Get File Of Type” to speed up execution and avoid localization bugs (where “public.rtf” is translated by default and breaks the action).

Changes the URL to use the input JSON directly instead of the “Get Dictionary From Input” action’s output, to preserve the order of the keys.

Thank you to @gluebyte for pointing out these issues! (https://www.reddit.com/r/shortcuts/comments/gqq43h/dictionaryjson_pretty_print/)


Past versions