Skip to content

Instantly share code, notes, and snippets.

@sgzijl
Created September 6, 2013 22:16
Show Gist options
  • Save sgzijl/6470712 to your computer and use it in GitHub Desktop.
Save sgzijl/6470712 to your computer and use it in GitHub Desktop.
datastructure to yaml & json (including a multiliner).
#!/usr/bin/env ruby
require 'yaml'
require 'json'
data = {
'somekey' => 'a value',
'another key' => [ 'an', 'array', 'of', 'values' ],
'multiliner key' => "line 1\n line 2\n line 3\n",
'a final key' => 'last value',
}
File.open('output.yaml', 'w') { |f| f.write data.to_yaml }
File.open('output.json', 'w') { |f| f.write data.to_json }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment