Skip to content

Instantly share code, notes, and snippets.

@xiaohanyu
Created September 1, 2014 06:29
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save xiaohanyu/67df9c2b958ac8fc0cf1 to your computer and use it in GitHub Desktop.
Save xiaohanyu/67df9c2b958ac8fc0cf1 to your computer and use it in GitHub Desktop.
convert yaml to json in ruby
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
@ribamar-santarosa
Copy link

limited....

 s = Set.new [1, 2, 3]
 => #<Set: {1, 2, 3}>

puts YAML::dump s
--- !ruby/object:Set
hash:
  1: true
  2: true
  3: true

JSON::dump YAML::load YAML::dump s
=> "\"#<Set:0x000000028792e8>\""

`

@Cinderhaze
Copy link

I just ran into this exact same problem....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment