Last active
August 29, 2015 14:02
-
-
Save briri/92c432da6793acbf0f52 to your computer and use it in GitHub Desktop.
Make JSON readable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is just a quick little script to use Ruby's JSON.pretty_generate() method without having to start an irb session. | |
# To call this JSON prettier just pass the flattened JSON in as an argument. | |
# To run it: | |
# 1) copy the code below into a file called json_viewer.rb | |
# 2) > ruby json_viewer.rb '{"foo":"bar","yadda":"yadda","blah":["blah1","blah2"]}' | |
require 'json' | |
unless ARGV[0].nil? | |
begin | |
json = JSON.parse(ARGV[0]) | |
puts JSON.pretty_generate(json) | |
rescue Exception => e | |
puts "You must supply a valid json string! (e.g. > ruby json_viewer '{\"foo\":\"bar\",\"yadda\":\"yadda\"}')" | |
end | |
else | |
puts "You must supply a json string! (e.g. > ruby json_viewer '{\"foo\":\"bar\",\"yadda\":\"yadda\"}')" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment