Pretty Print JSON
COMMENT
Pretty Print JSON by @FifiTheBulldog
Thank you to @gluebyte for providing valuable insight on the quirks of Shortcuts with dictionaries: https://www.reddit.com/r/shortcuts/comments/gqq43h/dictionaryjson_pretty_print/
This shortcut is inspired by the "JSON Validator and Beautifier" Instant Answer developed by the DuckDuckHack community for DuckDuckGo.
If the JSON is invalid, an error is returned.
SCRIPTING
If
Shortcut Input
does not have any value
SCRIPTING
Ask
Enter JSON to pretty print

Provided Input
SCRIPTING
End If

If Result
SCRIPTING
Get dictionary from
If Result

Dictionary
SCRIPTING
If
Dictionary
does not have any value
SCRIPTING
Show
Invalid JSON
SCRIPTING
Otherwise
TEXT
Tab character

Text
LIST

List
SCRIPTING

Chosen Item
SCRIPTING
If
Chosen Item
is
Tab Menu Item
TEXT
'\t'

Text
SCRIPTING
Otherwise
SCRIPTING
Get numbers from
Chosen Item

Numbers
SCRIPTING
End If

If Result
URL
data:text/html;charset=utf-8,<script>document.write(encodeURIComponent(JSON.stringify(
If Result
,null,
Space
)));</script>

URL
SCRIPTING
URL
Decode
URL

URL Encoded Text
SCRIPTING
Set name of
URL Encoded Text
to
JSON

Renamed Item
DOCUMENTS
Show
Renamed Item
in Quick Look
SCRIPTING
Choose from Menu

Menu Result
SCRIPTING
Copy JSON to Clipboard

Menu Result
SHARING
Copy
URL Encoded Text
to clipboard
SCRIPTING
Exit

Menu Result
SCRIPTING
End Menu

Menu Result
SCRIPTING
End If

If Result
Showcuts