JSON and data guides

XML to JSON: attributes, repeated elements and mixed content

Inspect the actual XML mapping before treating its JSON output as a stable API schema.

Nav Tools ·

Understand this converter mapping

Nav Tools keeps attributes under names prefixed with @_ and text under #text when an element needs both. Tag text remains a string.

Use a tiny element with an attribute before converting a large response; mapping conventions differ across libraries.

<item id="7">ready</item>
→ {"item":{"#text":"ready","@_id":"7"}}

Check single and repeated nodes

Repeated elements become an array in the current parser mapping; one occurrence can produce a scalar or object instead.

Test one item, two items and no items. A backend contract may need explicit array normalization rather than inferring cardinality from one fixture.

<root><item>A</item><item>B</item></root>
→ {"root":{"item":["A","B"]}}

Review namespaces and mixed content

Prefixes, namespace declarations and interleaved text carry XML semantics that a basic object mapping may not preserve.

For document-oriented XML such as text surrounding inline elements, use an XML-aware representation if ordering must survive a round trip.

Respect the supported input subset

The site rejects DTD and entity declarations and does not fetch external entities. Conversion is structural inspection, not execution of XML instructions.

Compare a reverse conversion with the original and confirm application meaning, not just successful parsing or equivalent indentation.

References

← JSON and data guides