Last Updated: February 25, 2016
·
536
· prune

display pretty json in shell

The utility http://stedolan.github.io/jq/ is a perfect tool to display pretty json on a shell.

For basic usage, simply pipe your output to jq :

cat file.json

{"took" : 54,"timed_out" : false,"_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"hits" : {"total" : 0,"max_score" : null,"hits" : [ ]  }}

Using JQ :

cat file.json | jq '.'

{
  "hits": {
    "hits": [],
    "max_score": null,
    "total": 0
  },
  "_shards": {
    "failed": 0,
    "successful": 2,
    "total": 2
  },
  "timed_out": false,
  "took": 6
}

You can compile jq or, if on Linux, download the pre-build binary package and copy it inside you PATH (/usr/local/bin for example).
Remember to make the finary executable :
shell chmod 755 jq

On a colorized shell, jq will add colors :
Picture

Read the doc as JQ can do A LOT MORE : http://stedolan.github.io/jq/manual/