Skip to content

Instantly share code, notes, and snippets.

@mikz
Created June 26, 2014 20:10
Show Gist options
  • Save mikz/adf676003bd0f5f456c4 to your computer and use it in GitHub Desktop.
Save mikz/adf676003bd0f5f456c4 to your computer and use it in GitHub Desktop.
coderwall tip

The problem

curling through web services can be tedious without some basic pretty printing. Let's see how easy it is to create aliases for pretty printing json/xml formats with Python's pygments library and xmllint/jsonp.

The Solution

alias xml='xmllint --format - | pygmentize -l xml -O encoding=utf8'
alias json='jsonpp | pygmentize -l json -O encoding=utf8''

Then just curl http://wservice.viabicing.cat/getstations.php\?v\=1 | xml or curl https://b83c5a5e-d575fbfbad2f.my.apitools.com | json to get nice XML/JSON output.

Preconditions

You need xmllint (part of libxml, on osx by default), pygments (easy_install pygments), jsonpp (brew install jsonpp on osx, http://jmhodges.github.io/jsonpp/ otherwise).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment