Skip to content

Instantly share code, notes, and snippets.

@alexalouit
Last active October 31, 2017 15:07
Show Gist options
  • Save alexalouit/402bdaf29174b133e5e23e7a3d2b9799 to your computer and use it in GitHub Desktop.
Save alexalouit/402bdaf29174b133e5e23e7a3d2b9799 to your computer and use it in GitHub Desktop.

from http://crisp.tumblr.com/post/2574967567/json-pretty-print-formatting-in-bbedit

Create the script (name it what you will, I named mine “PrettyJSON.py”), and save it in the “Unix Filters” folder for BBEdit (as described in the above article.

Copy some JSON into BBEdit, select it, and apply the filter.

UPDATE: If you are using BBEdit 10…

The "PrettyJSON.py" script should be placed here: “~/Library/Application Support/BBEdit/Text Filters”

Run the filter using the menu sequence: Text->Apply Text Filter->PrettyJSON

#!/usr/bin/python
import fileinput
import json
if __name__ == "__main__":
jsonStr = ''
for a_line in fileinput.input():
jsonStr = jsonStr + ' ' + a_line.strip()
jsonObj = json.loads(jsonStr)
print json.dumps(jsonObj, sort_keys=True, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment