Beautifying JSON data from the shell

Yesterday I bumped into a very handly utility to beautify JSON data directly from your command line.

Let’s say that, with a command, you are retrieving some data in JSON format1:

1
2
3
4
curl -X POST --user admin:admin \
http://localhost:2480/command/temp/sql/select%20from%20person

{"result":[{"@type":"d","@rid":"#9:2","@version":0,"@class":"person","name":"Luca"}, {"@type":"d","@rid":"#9:3","@version":0,"@class":"person"}, {"@type":"d","@rid":"#9:4","@version":0,"@class":"person"}]}

Of course, the result doesn’t really look readable, but thanks to a python utility we can directly expand and beautify our JSON by piping:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
curl -X POST --user admin:admin \
http://localhost:2480/command/temp/sql/select%20from%20person \
| python -mjson.tool

{
    "result": [
        {
            "@class": "person",
            "@rid": "#9:2",
            "@type": "d",
            "@version": 0,
            "name": "Luca"
        },
        {
            "@class": "person",
            "@rid": "#9:3",
            "@type": "d",
            "@version": 0
        },
        {
            "@class": "person",
            "@rid": "#9:4",
            "@type": "d",
            "@version": 0
        }
    ]
}

That’s all, folks!

Notes
  1. In my case, I am retrieving data from OrientDB, a NoSQL graph=document DB which handles data in JSON format over its HTTP interface

Hi there! I recently wrote an ebook on web application security, currently sold on leanpub, the Amazon Kindle store and gumroad.

It contains 160+ pages of content dedicated to securing web applications and improving your security awareness when building web apps, with chapters ranging from explaining how to secure HTTP cookies with the right flags to understanding why it is important to consider joining a bug bounty program.

Feel free to skim through some of the free chapters published on this blog and, if the content seems interesting enough to you, grab a copy on leanpub, the Amazon Kindle store, gumroad or simply checkout right down below!

Buy the Web Application Security ebook for $9.99

In the mood for some more reading?

...or check the archives.