Working with large JSON output can be a pill, especially when the server strips white-space or makes no effort at formatting the response for human-readability.
Having previously looked for a solution to make this easy, and not finding the right Google-majik to find it, I came across this article that talks about BBEdit’s Unix filtering abilities: BBEdit: Its Unix Support Doesn’t Suck Either, Part 2
I created this Python script that applies JSON pretty-print to text selected in the editor window:
#!/usr/local/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)
Voila! Human-readable JSON.
UPDATE: If you are using BBEdit 10…
[NOTE: Also works on TextWrangler, the free, light version of BBEdit.]
See also:
that just made my day much, much easier.