khym-w
Last Updated: February 25, 2016
·
3.283K
· felipeelias
F6faa607e4f541da71fbf8aea6f99a7a

Pretty print JSON responses with curl/ruby

Ruby only

curl -s "http://someapi.com/json" | ruby -rjson -e 'print JSON.pretty_generate(JSON.parse(STDIN.read))'

With awesome_print gem

curl -s "http://someapi.com/json" | ruby -rawesome_print -rjson -e 'ap JSON.parse(STDIN.read)'
Say Thanks
Respond

2 Responses
Add your response

17459
16937c1701f5a9e8e41bcce508913672

Thanks for this! Here's what I've got in my env:

function jcurl { curl $* | ruby -rawesome_print -rjson -e 'ap JSON.parse(STDIN.read)' }
export -f jcurl

Now just
jcurl -s "http://someapi.com/json"

over 1 year ago ·
24707
Gravatar

For color and more options, try piping to jq https://stedolan.github.io/jq/

curl -s "https://api.github.com" | jq

And then...

curl -s "https://api.github.com" | jq .user_search_url
over 1 year ago ·