-
-
Save patsanch/115b83a5061073d1d2ac to your computer and use it in GitHub Desktop.
convert yaml to json in ruby
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
require 'json' | |
require 'yaml' | |
input_filename = ARGV[0] | |
output_filename = input_filename.sub(/(yml|yaml)$/, 'json') | |
input_file = File.open(input_filename, 'r') | |
input_yml = input_file.read | |
input_file.close | |
output_json = JSON.dump(YAML::load(input_yml)) | |
output_file = File.open(output_filename, 'w+') | |
output_file.write(output_json) | |
output_file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment