khym-w
Last Updated: July 25, 2019
·
3.897K
· felipeelias

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)'

2 Responses
Add your response

17459

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

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 ·