Skip to content

Instantly share code, notes, and snippets.

@Filirom1
Created January 23, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Filirom1/7da2055d08da92e6b64e to your computer and use it in GitHub Desktop.
Save Filirom1/7da2055d08da92e6b64e to your computer and use it in GitHub Desktop.
xml2json with base64 decoding
require "rubygems"
require "crack"
require "json"
require "base64"
myXML = Crack::XML.parse(File.read(ARGV[0]))
def decode_base64(parent, myHash)
myHash.each {|key, value|
if value.is_a?(Hash)
decode_base64(key, value)
elsif value.is_a? String and value.include? "__base64__"
value.slice!("__base64__")
myHash[key] = Base64.decode64(value)
end
}
end
decode_base64(nil, myXML)
print JSON.pretty_generate(myXML)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment