Great JSON Beautifier as a BBEdit Text Filters

BBEdit.jpg

This morning I was looking at some JSON output from a service and realized that my hand-cleaning of JSON was really not a good use of my time. So I googled JSON beautification BBEdit and found this:

  #!/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)

It's a little python script that I can put into ~/Library/Application Support/BBEdit/Text Filters/, call it PrettyJSON.py and then restart BBEdit and get a wonderful reformatter in Text -> Apply Text Filter -> PrettyJSON.

It's impressive. Fast too. I had a pretty big JSON file and it made it look nice and readable in under a second. Very impressive. This is certainly something to keep around.