Today we are happy to announce our contribution to the open source world: the XML2JSON gem!
It all started out as a simple side project (more on that on a future post). One of the problems we faced was the XML format. Being rubyists, we don’t find ourselves at ease around XML, so we decided to convert it to JSON and then work with it.
Unfortunately we didn’t find an easy way to do it. No .to_json magic method :(.
Also, we didn’t find a gem or a library to deal with it. There are libraries out there that solve this problem. One of them is activesupport, that extends the Hash class with a from_xml method. The problem with this gem is that it does not handle the conversion the way we need. We wanted an almost transparent conversion from the XML format to the JSON one.
So we decided to write our own library.
These are the main points that make our library different.
We chose _attributes, _namespaces and _text out of our liking, but we provided a way to change them.
XML2JSON.config do |c|
c.attributes_key = "my_attributes"
c.namespaces_key = "my_namespaces"
c.text_key = "my_text"
When we finally got ourself a working version, we thought about every time we solved a big problem with a simple gem install. So we decided to share our little library with the world and turn it into a gem.
The gem is still in its early days of development. As of today it is version 0.4.0 and it can only be installed through github