Created
July 28, 2013 08:00
-
-
Save itamar/6097882 to your computer and use it in GitHub Desktop.
Convert XML to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'json' | |
| Hash.from_xml('<variable type="product_code">5</variable>').to_json # => "{\"variable\":\"5\"}" | |
| require 'net/http' | |
| s = Net::HTTP.get_response(URI.parse('http://stackoverflow.com/feeds/tag/ruby/')).body | |
| Hash.from_xml(s).to_json | |
| # for pretty output | |
| JSON.pretty_generate(Hash.from_xml('<variable type="product_code">5</variable>')) | |
| # http://stackoverflow.com/questions/1530324/ruby-xml-to-json-converter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment