Last Updated: September 29, 2021
·
4.912K
· 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

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 ·

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 ·