Json to xml converter

Hi folks,

is there any gem or code available for converting json data to xml data in ruby?

any help would be appreciated

I think you can use the rexml library from standard library:

Thank you .let me try it out

I created a gem (the nam is Shale) to map XML, JSON or YAML to Ruby model and convert it between different formats, you may find it useful. A quick example:

require 'shale'

class Person < Shale::Mapper
  attribute :name, Shale::Type::String
end

Person.from_json('{"name": "John Doe"}').to_xml

It will generate XML that looks like this (it’s customizable):

<person>
  <name>John Doe</name>
</person>

Full docs are available at https://shalerb.org/

1 Like

You can also use ActiveSupport. Here’s a script to convert JSON to XML using it: Active Support Core Extensions — Ruby on Rails Guides