Nicely Formatted JSON on the Command Line

You have a URL that outputs JSON, and you want to quickly see its contents from the shell, but nicely formatted, not the raw output wget spits; just do:

1
2
$ wget foo.com/bar.json -O - --quiet | ruby -rubygems -e \ 
  'require "json"; puts JSON.parse($stdin.gets).to_yaml'

I broke it up into two lines for easier reading, but you can type it all out in one line, or better yet, turn it into a shell script with a single URL argument.

Comments