"ruby xml to json converter?" Code Answer


a simple trick:

first you need to gem install json, then when using rails you can do:

require 'json'
require 'active_support/core_ext'
hash.from_xml('<variable type="product_code">5</variable>').to_json #=> "{"variable":"5"}"

if you are not using rails, then you can gem install activesupport, require it and things should work smoothly.


require 'json'
require 'net/http'
require 'active_support/core_ext/hash'
s = net::http.get_response(uri.parse('https:///feeds/tag/ruby/')).body
puts hash.from_xml(s).to_json
By zupo on May 17 2022

Answers related to “ruby xml to json converter?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.