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.

Make attributes and namespaces explicit

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)
BoundaryWhat to check
attributeKeep attributes separate from element values and decide collision rules.
namespacePreserve the namespace URI; do not guess an undefined prefix.
orderUse an array or other explicit representation when sibling order matters.
repeated elementDo not overwrite repeated elements with the last value; choose an array policy.

Mixed content is a loss risk

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.

Open the existing XML-to-JSON converter

Review cases

caseoutcomecheck
attribute-boundaryexplicit-attribute-policyName the attribute key and collision policy.
namespace-identityuri-preserved-prefix-may-changePreserve the URI, not just the prefix.
sibling-orderorder-preservedKeep meaningful child order in an array.
repeated-elementarray-policyChoose an explicit array policy.
mixed-contentloss-riskDo not flatten interleaved text and children.
unsupported-or-uploadrejectReturn unclear mappings or uploads.

Do not send input

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.