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)'
Written by Felipe Elias Philipp
Related protips
2 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#