A quick ruby command line to pretty-print piped json.
Put this somewhere in your path, with chmod +x
, then:
curl http://myapp.com/stuff.json | json
A quick ruby command line to pretty-print piped json.
Put this somewhere in your path, with chmod +x
, then:
curl http://myapp.com/stuff.json | json
#!/usr/bin/env ruby | |
require 'rubygems' # 1.8.7 | |
require 'bundler' | |
Bundler.setup | |
require 'json' | |
if STDIN.tty? | |
puts 'your_command | json [--no-color]' | |
else | |
data = JSON.parse(STDIN.read) | |
if ARGV.include?('--no-color') | |
puts JSON.pretty_generate(data) | |
else | |
require 'ap' | |
ap data | |
end | |
end |
You can also simply add the following to bashrc or zshrc
function json {
ruby -rjson -e 'puts JSON.pretty_generate(JSON.parse(STDIN.read))'
}
Doesn't give you the color or the help, but works well enough.
Do you need a Bundler?