Skip to content

Instantly share code, notes, and snippets.

@andycmaj
Created May 21, 2013 04:39
Show Gist options
  • Save andycmaj/5617516 to your computer and use it in GitHub Desktop.
Save andycmaj/5617516 to your computer and use it in GitHub Desktop.
Convert Swagger YAML api definition to JSON
#!/usr/bin/env ruby
require 'yaml'
require 'json'
# yaml file with api definition
in_file_name = ARGV[0]
# json file output
out_file_name = ARGV[1]
# read in yaml
yaml = File.read(in_file_name)
# convert yaml to hash
hash = YAML::load(yaml)
# convert hash to string
json = hash.to_json
# write string to out_file_name
File.open(out_file_name, 'w') {|f| f.write(json) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment