Last active
June 20, 2018 09:56
-
-
Save Moligaloo/2e853f01dc02f9bb80c4 to your computer and use it in GitHub Desktop.
Pretty reformat of JSON file
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
#!/usr/bin/env ruby | |
json_file = ARGV[0] | |
if json_file == nil | |
puts "Usage: #{$PROGRAM_NAME} <json file> [out_file]" | |
exit | |
end | |
require 'json' | |
begin | |
object = JSON.parse(IO.read json_file) | |
out_file = ARGV.fetch(1, json_file) | |
IO.write out_file, JSON.pretty_generate(object) | |
rescue JSON::ParserError => e | |
puts "parse failed" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment