Format JSON in terminal in copy to clipboard

If you work with json object, it is highly likely that you need to pretty print json object very often. There are sites like json beautifier or similar which can do it for you.

But what if you can indent json string via your terminal and copy to clipboard.

Here is a simple bash function which could be used to convert json string to indented json object.

Asuming you have python2.6+ installed in your system.

    echo "$1" | python -m json.tool 

If you have xclip installed, you also can make indented json copied to clipboard.

    echo "$1" | python -m json.tool | xclip -selection c

Install xclip via,

sudo apt-get install xclip