Convert XML to JSON using Ruby and ActiveSupport

Jun 27, 2011 Software Engineering 3,856 views
Convert XML to JSON using Ruby and ActiveSupport

How to convert XML to JSON using Ruby and ActiveSupport:

#! /usr/bin/env ruby

    require 'rubygems'
    require 'active_support/core_ext'
    require 'json'
    
    xml = File.open(ARGV.first).read
    json = Hash.from_xml(xml).to_json
    
    File.open(ARGV.last, 'w+').write json