XML and JSON

The conversion to JSON from XML changes the structure of the document. Take this into account when making hierarchical queries. The primary structural change is that attributes become elements in JSON, and the content of a mixed element is set in a content key.

For example, consider the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>testA</b>
      <c>12345</c>
   </a>

After the conversion, the following corresponding JSON document is created:

{
    "a":{
        "b":"testA",
        "c":"12345",
        "name":"bob"
    }
}

Another example in which the <a> element has content is as follows:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>testA</b>
      <c>12345</c>
      Test
   </a>

After the conversion, the following corresponding JSON document is created:

{
    "a":{
        "content":"\nTest",
        "b":"testA",
        "c":"12345",
        "name":"bob"
    }
}

iWay Software