9idskq
Last Updated: February 25, 2016
·
427
· nat-n
Img 2183

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
Say Thanks
Respond