Skip to content

Simple API that converts dynamic XML feeds to JSON through a URL or pasting the raw XML data. Made 100% in PHP.

Notifications You must be signed in to change notification settings

factmaven/xml-to-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

XML to JSON API


Overview

This is an API that converts XML to JSON. If you are using an XML and don't want to go through the hassle of modifying it to be a JSON, this is the API for you. Simply submit the URL or raw data of the XML through the API and it will instantly convert your old feed to a JSON.

"Unfortunately, XML exists. For whatever reason, somebody once thought it was a good idea and now we’re stuck with it. Since most modern applications and APIs use JSON instead, it’s often necessary to convert XML into JSON..."

Tamlyn Rhodes

Some tools are not great at parsing XML data (such as en-US from locale). Specifically when there is data that within the attributes for example:

<item contentType="tv_episode" contentId="df9c946a-e891-11ea-adc1-0242ac120002">
    <pubDate>2020-08-27T11:39:57-05:00</pubDate>
    <title locale="en-US">Episode Title</title>
    <description locale="en-US">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description>
    <rating systemCode="us-tv">TV-14</rating>
    <artwork url="https://example.com/image.jpg" type="tile_artwork" locales="en-US" />
</item>

While there are plenty of XML to JSON converters available, none of them would convert a feed with live data that's constantly changing and updating its layout.

That's where the XML to JSON API comes in, it converts dynamic XML feeds to JSON. As a result, it will be able to parse those attribute values in a JSON format:

"item": [
    {
        "@contentType": "tv_episode",
        "@contentId": "df9c946a-e891-11ea-adc1-0242ac120002",
        "pubDate": "2020-03-26T11:39:57-05:00",
        "title": {
            "@locale": "en-US",
            "#text": "Episode Title"
        },
        "description": {
            "@locale": "en-US",
            "#text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
        },
        "rating": {
            "@systemCode": "us-tv",
            "#text": "TV-14"
        },
        "artwork": {
            "@url": "https://example.com/image.jpg",
            "@type": "tile_artwork",
            "@locales": "en-US"
        }
    }
]

How to Use

This API is currently available for use by visiting:

Then you can do one of the following:

Option 1: Submitting the XML URL

Add the URL to your XML by adding the ?xml= parameter and then the full URL of your feed. It's important that you must start with http:// or https:// for it to work.

Example

https://api.factmaven.com/xml-to-json?xml=https://example.com/feed.xml

Option 2: Paste Raw XML Data

Paste the raw XML data after the ?xml= parameter. Do note that there is a limit to how much you can load, it's best for smaller XMLs.

Example

https://api.factmaven.com/xml-to-json?xml=<item contentType="tv_episode" contentId="df9c946a-e891-11ea-adc1-0242ac120002"><pubDate>2020-08-27T11:39:57-05:00</pubDate><title locale="en-US">Episode Title</title><description locale="en-US">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description><rating systemCode="us-tv">TV-14</rating><artwork url="https://example.com/image.jpg" type="tile_artwork" locales="en-US" /></item>

Contributors

We would like to thank those who helped us improve our API with new features and fixing bugs. If you have any suggestions to improve our API or find any bugs, let us know here. Your feedback and suggestions are always welcome.