Pretty format JSON console output

Recently I started reading a little bit about CouchDB. So after I installed CouchDB on my machine I started reading the Getting Started section of the documentation. There they explain how to interact with CouchDB using curl. For every curl command they also provide the corresponding answer of the CouchDB server, which is pretty nice if you’re just reading without typing the commands yourself or reassuring if you do type the commands while following along.

But: In my own shell the JSON responses are not as nicely formatted as in the docs.

This is of course not surprising, because that is not curl’s task to do. So I asked: “Isn’t there a simply way of doing that?”. Probably not so surprisingly: there is!

The Python JSON tools module

There is a Python package called json_tools on PyPI.

The nice thing: If you run the library module as a script (see the -m option in python --help) it will read JSON data input from stdin and pretty print it to stdout.

So instead of this:

you can do this:

This is a lot nicer to read and all you need for it is to have Python and the json_tools module installed.