XML / JSON / handoff guide
Hand XML to JSON without losing attributes or order
A JSON conversion can still lose meaning. Separate attributes, namespace identity, sibling order, repeated elements, and mixed content before handoff.
XML / JSON / handoff guide
A JSON conversion can still lose meaning. Separate attributes, namespace identity, sibling order, repeated elements, and mixed content before handoff.
Do not silently merge XML attributes into element text. Choose an attribute key policy. A namespace is identified by its URI, not by its prefix; prefixes can change while the URI meaning must remain stable.
<item xmlns:x="urn:example" x:id="7">A</item>
→ element text: "A"
→ attribute: x:id = "7"
→ namespace URI: urn:example (prefix x may change)| Boundary | What to check |
|---|---|
| attribute | Keep attributes separate from element values and decide collision rules. |
| namespace | Preserve the namespace URI; do not guess an undefined prefix. |
| order | Use an array or other explicit representation when sibling order matters. |
| repeated element | Do not overwrite repeated elements with the last value; choose an array policy. |
In <p>before<b>bold</b>after</p>, text and child elements are interleaved. Flattening them to one JSON string can lose order and boundaries. Agree on a parts-array representation before handoff.
The existing local XML-to-JSON converter helps inspect a conversion. This guide makes loss risks explicit; it does not claim every XML dialect can be losslessly converted.
| case | outcome | check |
|---|---|---|
attribute-boundary | explicit-attribute-policy | Name the attribute key and collision policy. |
namespace-identity | uri-preserved-prefix-may-change | Preserve the URI, not just the prefix. |
sibling-order | order-preserved | Keep meaningful child order in an array. |
repeated-element | array-policy | Choose an explicit array policy. |
mixed-content | loss-risk | Do not flatten interleaved text and children. |
unsupported-or-upload | reject | Return unclear mappings or uploads. |
This guide does not upload XML, infer a schema, or call an external XPath service. Use harmless fixtures and do not paste production secrets, credentials, or personal data.