Skip to content

Instantly share code, notes, and snippets.

@Moligaloo
Last active June 20, 2018 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Moligaloo/2e853f01dc02f9bb80c4 to your computer and use it in GitHub Desktop.
Save Moligaloo/2e853f01dc02f9bb80c4 to your computer and use it in GitHub Desktop.
Pretty reformat of JSON file
#!/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