How XML data is converted to JSON

Description

The Connect uses JSON as the common data format to transfer messages between components.

XML data may be converted to JSON in the Connect or, if needed, there are a number of methods that can be used to send the XML through as XML.

How XML is converted to and from JSON

XML data coming into the system is parsed into a JSON using the following settings:

Setting Name Value

trim

false

normalize

false

explicitArray

false

normalizeTags

false

attrkey

"_attr"

tagNameProcessors

Here we replace all : with - to avoid conflicts in mapper processing

Some examples of this transformation display below:

Incoming XML

<purchaseOrder orderDate="1999-10-20">
    <shipTo country="US">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
    </shipTo>
    <billTo country="US">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
    </billTo>
    <comment>Hurry, my lawn is going wild!</comment>
    <items>
        <item partNum="872-AA">
            <productName>Lawnmower</productName>
            <quantity>1</quantity>
            <USPrice>148.95</USPrice>
            <comment>Confirm this is electric</comment>
        </item>
        <item partNum="926-AA">
            <productName>Baby Monitor</productName>
            <quantity>1</quantity>
            <USPrice>39.98</USPrice>
            <shipDate>1999-05-21</shipDate>
        </item>
    </items>
</purchaseOrder>

Resulting JSON

{
  "purchaseOrder": {
    "_attr": {
      "orderDate": "1999-10-20"
    },
    "shipTo": {
      "_attr": {
        "country": "US"
      },
      "name": "Alice Smith",
      "street": "123 Maple Street",
      "city": "Mill Valley",
      "state": "CA",
      "zip": "90952"
    },
    "billTo": {
      "_attr": {
        "country": "US"
      },
      "name": "Robert Smith",
      "street": "8 Oak Avenue",
      "city": "Old Town",
      "state": "PA",
      "zip": "95819"
    },
    "comment": "Hurry, my lawn is going wild!",
    "items": {
      "item": [
        {
          "_attr": {
            "partNum": "872-AA"
          },
          "productName": "Lawnmower",
          "quantity": "1",
          "USPrice": "148.95",
          "comment": "Confirm this is electric"
        },
        {
          "_attr": {
            "partNum": "926-AA"
          },
          "productName": "Baby Monitor",
          "quantity": "1",
          "USPrice": "39.98",
          "shipDate": "1999-05-21"
        }
      ]
    }
  }
}

And here is more complicated SOAP envelope sample, incoming XML:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
        <Configuration Supplier="TT" FlowId="abc123">
            <ApiHost>https://int.foo.com</ApiHost>
            <ApiKey>foo</ApiKey>
            <ApiSecret>bar</ApiSecret>
            <Currency>USD</Currency>
        </Configuration>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <OTA_HotelAvailRQ xmlns="http://www.opentravel.org/OTA/2003/05" EchoToken="2590cbc9-50f2-4161-babb-c97cc07dfe7d"
                          PrimaryLangID="en-US" TimeStamp="2016-12-05T01:10:14.057-08:00" Version="1.0">
            <POS>
                <Source>
                    <RequestorID ID="GOOGLE" ID_Context="BAR" Type="18"/>
                </Source>
            </POS>
        </OTA_HotelAvailRQ>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Resulting JSON:

{
  "SOAP-ENV-Envelope": {
    "_attr": {
      "xmlns:SOAP-ENV": "http://schemas.xmlsoap.org/soap/envelope/"
    },
    "SOAP-ENV-Header": {
      "Configuration": {
        "_attr": {
          "Supplier": "TT",
          "FlowId": "abc123"
        },
        "ApiHost": "https://int.foo.com",
        "ApiKey": "foo",
        "ApiSecret": "bar",
        "Currency": "USD"
      }
    },
    "SOAP-ENV-Body": {
      "OTA_HotelAvailRQ": {
        "_attr": {
          "xmlns": "http://www.opentravel.org/OTA/2003/05",
          "EchoToken": "2590cbc9-50f2-4161-babb-c97cc07dfe7d",
          "PrimaryLangID": "en-US",
          "TimeStamp": "2016-12-05T01:10:14.057-08:00",
          "Version": "1.0"
        },
        "POS": {
          "Source": {
            "RequestorID": {
              "_attr": {
                "ID": "GOOGLE",
                "ID_Context": "BAR",
                "Type": "18"
              }
            }
          }
        }
      }
    }
  }
}

© 2015- Squiz Pty Ltd