Howto beautify xml and json from a bash script

Sometime may happens you need to beautify xml or json from a bash script. So here there are two methods to easily obtaing a pretty print of your data:

Command to beautify XML

cat filename.xml | xmllint --format -

Command to beautify JSON

cat filename.json | python -m json.tool

In case you miss above tools on your system, they can be installed with

sudo apt-get install libxml2-utils
sudo apt-get install python
sudo pip install simplejson

Good luck!

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.