Skip to content

uvlad7/xml2json-rb

Repository files navigation

Gem Version Gem Gem Tests Docs Release

Xml2Json

A tiny Ruby wrapper for the Rust xml2json lib which allows to convert xml strings to json and vise versa.

Table of Contents

Prerequisites

This gem is written in Rust and provides precompiled binary versions for the most common architectures and operation systems. If there is no suitable version or if you don't want to use precompiled libraries, you need to install cargo to compile it from source.

Warning
This won't work for local development with rake compile

If you have some weird setup with cargo named differently, of it's not in your PATH, you can pass a command to be evaluated via environment variable CARGO, for example:

$ export CARGO=cargo1_72_1

or simply

$ CARGO=/path/to/cargo gem install xml2json-rb

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add xml2json-rb --require xml2json

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install xml2json-rb

Usage examples

require "xml2json"

puts Xml2Json::Xml.build_pretty('{"a": 1, "b": "2"}')
# <?xml version="1.0"?>
# <root>
#   <a>1</a>
#   <b>2</b>
# </root>
puts Xml2Json::Json.build("<root><a>1</a><b>2</b></root>", explicit_array: false)
# {"root":{"a":"1","b":"2"}}

See specs for more examples.

Documentation

YARD docs are available on rubydoc.info for the latest released version and on pages.github.com for the most recent changes in master

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub.

Releases

This project uses Semantic Versioning and adheres to the Keep a Changelog guidelines.

License

The gem is available as open source under the terms of the MIT License.