XML to JSON

Convert the body of POST requests from XML to JSON

Description

As the name points out the XML to JSON add-on is a simple tool that converts the body of your POST requests from XML to JSON before they reach your tagging server.

Since most of the tags and analytics tools work with JSON, this add-on removes the hassle of dealing with the XML data conversion on your tagging server.


Implementation

To enable the XML to JSON add-on, go to your container on sprtags.io > Add-ons > XML to JSON enable it and click on save.


XML to JSON screenshot

To make use of this add-on and convert XML input into JSON output, the only thing you need to do is add xml right after your server container url.

Send the POST request with XML body that you would like to convert to: {your tagging url}/xml/ {the original path} and you will receive it with JSON format on your tagging server.


Here we have 2 sample requests, one with the XML to JSON enabled and one without it:

Curl without XML to JSON conversion:



curl -X POST \ https://{your_tagging_url}/hello \ -H 'Content-Type: application/xml' \ -H 'x-gtm-server-preview: {Your X-Gtm-Server-Preview HTTP header}' \ -d '<root><person><name>John Doe</name><age>30</age></person></root>'

Curl with XML to JSON conversion:



curl -X POST \ https://{your_tagging_url}/xml/hello \ -H 'Content-Type: application/xml' \ -H 'x-gtm-server-preview: {Your X-Gtm-Server-Preview HTTP header}' \ -d '<root><person><name>John Doe</name><age>30</age></person></root>'

Checkout out our How-To page to:
  • find your tagging url
  • X-GTM-Server-Preview HTTP header
  • execute curl commands

In the example below we send a xml request to /xml/hello> that will arrive to /hello:

In the left image you see the request without /xml or when add-on is disabled and in the right image you see the successfully converted request to JSON with /xml:

XML to JSON screenshot