XML and JSON model data differently — see JSON vs YAML vs XML for the tradeoffs that matter.
How elements are mapped
- An element with only text becomes a string (or number/boolean/null if type-inferable).
- An element with attributes
<a x="1">hi</a>becomes{ "@x": 1, "#text": "hi" }. - Two elements with the same name under a parent are folded into an array.
- The root element is preserved as the top-level key.
When you need XML converted to JSON
Modern web clients prefer JSON because it deserialises straight into JavaScript objects. If you're talking to a legacy SOAP service, an Atom/RSS feed, or any system that emits XML, converting to JSON gives you something easier to query with the JSONPath tester, validate with a JSON Schema, or pretty-print with the JSON formatter.
FAQ
Are namespaces preserved?
ns:foo. We don't expand them to URLs.