XML parsing uses the browser’s own DOMParser — no external library, and no entity expansion beyond what the browser allows.
XML parsing uses the browser’s own DOMParser — no external library, and no entity expansion beyond what the browser allows.
SOAP services, RSS feeds and older enterprise systems still speak XML. Converting between the two formats is lossy unless attributes are handled properly, so this maps XML attributes to @-prefixed keys and text content to #text, which means the round trip keeps its meaning. XML parsing uses the browser's own DOMParser rather than a hand-rolled parser.
XML attributes become @-prefixed keys and text becomes #text, so the round trip keeps meaning.
Repeated sibling elements collapse into a JSON array, and expand back into elements.
DOMParser does the reading — no third-party XML library, no hand-rolled parser.
Root element name, indentation, and whether to emit the XML declaration.
As keys prefixed with @ — so <item sku="K"> becomes {"@sku": "K"}. Element text alongside attributes becomes "#text". Converting back turns them into real attributes again.
Repeated sibling elements with the same name become a JSON array, and an array in JSON becomes repeated elements on the way back.
XML does. If your JSON has one top-level key it is used as the root element; otherwise the document is wrapped in the root element you name.