XML and JSON describe data with different building blocks, so every converter has to make choices, and two tools will often disagree on the same input. The main mismatches are:
- Attributes versus elements.
<price currency="USD">carries data in two places. JSON has only keys, so attributes need a marker that keeps them apart from child elements with the same name. - Order. XML element order is significant; JSON object keys are officially
unordered. Interleaved siblings such as
<a/><b/><a/>end up as oneaarray and onebkey, so the original sequence is lost. - Mixed content. In
<p>Hello <b>world</b>!</p>the text and the element are interleaved. JSON has no natural way to say where the<b>sat inside the sentence. - Arrays of one. This is the classic bug. A converter only sees an array when
an element repeats, so an order with two
<item>children produces"item": [ ... ], but an order with one item produces"item": { ... }. Code that doesorder.item.forEach(...)works in testing and then fails in production on the first single-item order.
The fix for the last one is to tell the converter which elements are lists. Type the tag names into Force arrays, separated by commas, and they are always emitted as arrays, even with one child. If you consume the JSON in code, do this for every element your schema allows to repeat.