Pretty print a json file
Snippet
Written with a loving hand by kitt some time around 10:21 on 6 August 2015
JSON comes over the wire with minimal spaces, making human parsing of the object difficult. The json lib provides an easy way to reformat it into an indented format.
Remember to use #!/usr/bin/env
so that any rbenv
or rvm
specific versions of ruby will be used.
Dump this into a file, say, format-json.rb
, and use with:
format-json.rb my-squashed.json > nicely-readable.json
Usage:
#!/usr/bin/env ruby require 'json' exit if ARGV[0].nil? puts JSON.pretty_generate(JSON.parse(File.read(ARGV[0])))
Add new comment