This post is just a short tidbit, a tip how to pretty print JSON when using Curl.

The Solution

As an example, I'll request my latest post as JSON and pretty print it.

curl -H "Accept: application/json" | python -m json.tool

In the example, we first make a HTTP GET request with Curl. Additionally, I set Curl only to accept application/json. This way my site will produce json, not html which is the default. Then I pipe the result of the request to a python's json library. This approach should work as long as you have Curl and Python installed (as is the case with OS X and most *nix systems).

How about a shell script

Create the script file:


Add the curl-command to the script, use $1 to capture the first command line argument:

curl -H "Accept: application/json" $1 | python -m json.tool

Add execution permissions for the script:

chmod u+x


Common Issue

There are several posts about this very same issue:

Now, if you prefer an online tool, there are several of those available too. Here's two: