In general, XML to JSON conversion is a tricky problem. In the case of Campaign, it's even trickier since the structure of the XML documents is defined by Campaign, and is therefore imposed.
In Campaign, collections of objects are represented by multiple XML elements. There isn't generally a containing element. For instance in the example below, we have books. Books have an author and chapters.
<book title="A confederacy of dunces"> <author>John Kennedy Toole</author> <chapter name="Chapter I" pages="20"> </chapter> <chapter name="Chapter II" pages="34"> </chapter> </book>
As you can see, there is one "author" element and two "chapter" elements. But can there be multiple author elements? Well it depends, and this depends on the schema, whether the schema author has decided that "author" is a single element or can be a collection (unbound="true"). But looking a the XML only, it's impossible to tell. We're going to assume that the author here is not a collection, it is simply a string property that has been implemented as an XML element and not as an XML attribute. The corresponding SimpleJson will be the following.
{ "$author": "John Kennedy Toole", "chapter": [ { "name": "Chapter I", "pages": 20 }, { "name": "Chapter II", "pages”: 3 }, ] }
So far, so good, but what if the book only had one chapter?
<book title="A confederacy of dunces"> <author>John Kennedy Toole</author> <chapter name="Chapter I" pages="20"> </chapter> </book>
This becomes trickier because now we have two alternatives: in JSON the "chapter" property can be either an array of one element (which is what is expected) or the element itself
{ "$author": "John Kennedy Toole",
"chapter": [
{
"name": "Chapter I",
"pages": 20
] }
// or
{ "$author": "John Kennedy Toole",
"chapter": {
"name": "Chapter I",
"pages": 20
} }
And what if a particular book has no chapters? There will not even be any <chapter> elements in the XML. How can the SDK decide if it should create an empty chapters array or leave the chapter property undefined.
This is really painful from a user point of view at it can lead to complex and error prone code: every time a JSON property is accessed, one has to wonder what type it is and whether it is the right type