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
}
}
}
]
}
Written by Alexandru Topliceanu
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#