Last Updated: September 19, 2018
·
9.13K
· topliceanu

Pretty print json responses returned by curl requests in command line

Most of the APIs I usually use return JSON strings as response body. Eg:

$ curl -XGET http://awesome.com/api/v1/data
{"x": 1, "y": [{"z": 2}, {"u": {"v": {"t": 3}}]}

When the JSON is large it becomes hard to figure out the structure of the nested document. This is important when debugging JSON endpoints.

An easy way to do this on envs which have python installed is to pipe the output to python -m json.tool like so:

$ curl -XGET http://awesome.com/api/v1/data | python -m json.tool
{
    "x": 1,
    "y": [
        {
            "z": 2
        },
        {
            "u": {
                "v": {
                    "t": 3
                }
            }
        }
    ]
}