Skip to content

Instantly share code, notes, and snippets.

@nuttt
Last active December 28, 2015 07:28
Show Gist options
  • Select an option

  • Save nuttt/7464203 to your computer and use it in GitHub Desktop.

Select an option

Save nuttt/7464203 to your computer and use it in GitHub Desktop.
Convert all xml file in folder to json
require 'active_support/core_ext'
require 'json'
files = Dir.glob(File.join('.', "*.xml"))
files.to_enum.with_index(1).each do |file, i|
puts "converting #{i} of #{files.length}: #{file}"
xml = File.read(file)
f = File.open(file+".json", 'w')
f.write(Hash.from_xml(xml).to_json)
f.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment