Convert an XML document into a JSON object. Attributes become @name keys and repeated child elements are grouped into arrays, so deeply nested documents such as SOAP responses or RSS feeds can be read like a JavaScript object.
Use it to understand the structure of an XML response from a legacy system before handling it in front-end or Node.js code, or to turn it into a JSON mock for tests. Parsing is done by your browser's DOMParser.
XML box or drop an .xml file onto it. The <?xml ...?> declaration is optional.Result, keyed by the root element name, and copy it.<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetRateResponse>
<rate currency="USD">1342.5</rate>
<note><![CDATA[rates < 1 hour old]]></note>
<holiday/>
</GetRateResponse>
</soap:Body>
</soap:Envelope>{
"soap:Envelope": {
"@xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
"soap:Body": {
"GetRateResponse": {
"rate": {
"@currency": "USD",
"#text": "1342.5"
},
"note": "rates < 1 hour old",
"holiday": null
}
}
}
}The currency attribute became @currency, and the number inside the element went into #text as the string "1342.5". The < inside CDATA is kept as plain text, and the empty <holiday/> is null.
{ "rootName": ... }, preserving the original root element name.@-prefixed keys; text that sits alongside child elements or attributes goes under #text.null.soap:Body and xmlns declaration attributes are kept as keys.Seen as JSON, the Envelope → Body → Response nesting shows exactly where the payload sits, and that path maps directly to property access in your code.
Check how many item entries a feed has and where the url attribute of enclosure lives before writing the parsing code.
When building a BFF or adapter around an XML API, converting real responses to JSON gives you test fixtures straight away.
<price>12.5</price> is not converted to a number, so convert where needed.Array.isArray in code.<p>hello <b>world</b> again</p> has its text merged into one #text, losing where it sat between elements.XML carries no type information beyond text, so the tool does not guess and keeps strings. That way code values like "00123" are never mangled into numbers.
There is no option for this. Wrapping in code with Array.isArray(x) ? x : [x] is the simplest fix.
The JSON to XML tool uses the same @ and #text conventions, so feeding it this output produces XML again. Comments, the CDATA distinction and the position of text in mixed content are not restored.