WORKED EXAMPLE · SYNTHETIC INPUT
Keep XML attributes and empty repeated elements in JSON
A simple XML converter can drop attributes on leaf nodes or overwrite an empty first value when a second element has the same name. Inspect both before using the output as test data.
These inputs demonstrate reproducible behaviour; they are not customer incidents or evidence of real usage.
Reproducible input
<root><item id="1"></item><item id="2">Ada & Grace</item><empty/><empty>value</empty></root>
Steps
- Load the example and convert it to JSON.
- Check root.item: it contains two objects, with @id values "1" and "2". Their #text values are "" and "Ada & Grace".
- Check root.empty: the array must be ["", "value"], not just "value". Text remains string; no number inference is performed.
- Replace the input with <p>Hello <b>Ada</b>!</p>. Conversion reports mixed content. Open the XML formatter to keep that text and child order instead.
Expected result
Attributes, empty values and repeated same-name siblings remain visible. Invalid XML never becomes a JSON parsererror result. Changing input clears the previous output.
Limits and manual checks
This is a grouped mapping, not a reversible XML document model. Comments and processing instructions are ignored, CDATA becomes text, and ordering across different child names is lost. Mixed content and DTDs are rejected. Browser XML parsing normalizes some whitespace and entities; do not use this conversion to verify signatures.
Technical reference