Additional Tools

A while ago I wrote a simple tool for pretty-printing JSON data. Over time I found it handy to have around when working with various applications and services that generate JSON output. You might find it handy when you are working with JSON. Here it is:

#!/usr/bin/python

import sys
import json

def main():

        try:

                data = sys.stdin.readline()
                dd = json.loads(data)

        except:

                sys.stderr.write("Error: %s" % str(sys.exc_info()[0]))
                sys.stderr.write("\nI got no data, badly formatted JSON, or something that is not JSON.")

                sys.exit()

        print json.dumps(dd, indent=2)

if __name__ == "__main__":
    main()


loading table of contents...