veojzg
Last Updated: February 25, 2016
·
464
· spiegela

Use fancy aliases to reformat markup

Looking at serialized data? I use a combination of tools and fancy shell aliases to make this easier:

Install a couple of tools:

  • Make sure you have python
  • Pygments (python lib)
  • Libxml2 (to get xmllint)

Then add your aliases to your (zsh|bash)rc file (I use xp for XML Print and jp for JSON Print):

# JSON Print
alias jp="python -mjson.tool | pygmentize -f terminal256 -O style=native -g |less -r"

# XML Print
alias xp="xmllint --recover --format - | pygmentize -f terminal256 -O style=native -g |less -r"

Then enjoy browsing your serialized data all prettied up from the command-line:

# Yer JSON is Perrty
 curl -XGET -H "Content-Type:application/json" http://<some url>.json | jp

# Yer XML is Perrty
 curl -XGET -H "Content-Type:application/xml" http://<some url> | xp

Adapted from an SO answer