Prettify JSON in the command line with Ruby
This bash one liner can be used to pretty print json from a pipe
json_source | ruby -e "require 'json'; puts JSON.pretty_generate(JSON.parse(ARGF.read))"
or from a file
ruby -e "require 'json'; puts JSON.pretty_generate(JSON.parse(ARGF.read))" datafile.json
Create an alias for easy of use.
alias prettyjson="ruby -e \"require 'json'; puts JSON.pretty_generate(JSON.parse(ARGF.read))\""
prettyjson datafile.json
cat datafile.json | prettyjson
Written by nat
Related protips
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#