Skip to content

Latest commit

 

History

History

ruby

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

XML to JSON API - Ruby Gem

XML to JSON is an XML to JSON converter API that turns raw XML strings into structured JSON objects. Send any valid XML payload to receive an organized JSON tree preserving tags, attributes, and child elements.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_xmltojson'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_xmltojson

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_xmltojson'

# Initialize the client
client = APIVerve::Xmltojson::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({ xml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>" })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ xml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>" })
  puts response["data"]
rescue APIVerve::Xmltojson::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Xmltojson::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Xmltojson::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "note": {
      "children": [
        {
          "to": {
            "content": "Tove"
          }
        },
        {
          "from": {
            "content": "Jani"
          }
        },
        {
          "heading": {
            "content": "Reminder"
          }
        },
        {
          "body": {
            "content": "Don't forget me this weekend!"
          }
        }
      ]
    }
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.