Skip to content

Instantly share code, notes, and snippets.

@kei-q
Created April 29, 2016 05:54
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 kei-q/5507d510ae5b68ca315f98844f2f612d to your computer and use it in GitHub Desktop.
Save kei-q/5507d510ae5b68ca315f98844f2f612d to your computer and use it in GitHub Desktop.
jsonをrubyのhashに読み書きしやすい形で出力するスクリプト
#!/usr/bin/env ruby
# require: awesome_print, rubocop
require 'ap'
require 'json'
if ARGV.count != 2
puts 'usage: ./script.rb <input_json_file> <output_sour_file_name>'
exit 1
end
INPUT_JSON_FILE = ARGV[0]
OUTPUT_SOURCE_FILE = ARGV[1]
contents = File.read(INPUT_JSON_FILE)
output = JSON.parse(contents, symbolize_names: true).ai(index: false, plain: true, indent: 2)
File.write(OUTPUT_SOURCE_FILE, output)
system("rubocop #{OUTPUT_SOURCE_FILE} --auto-correct --format disabled")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment