Output appears here.
XML to JSON converts an XML document into a JSON object, with control over how attributes, repeated elements and numeric text are represented. It is for developers consuming SOAP services, RSS feeds, sitemaps and legacy APIs from JavaScript or any JSON-first tooling. The XML is parsed in your browser, and nothing is uploaded.
How to convert XML to JSON
- Paste XML, drop an
.xmlfile, or press ⌘/Ctrl O. The XML is checked for well-formedness first, and errors show their line and column. - Choose an Attribute prefix, and decide whether to Convert numbers & booleans and make Repeated elements always arrays for a predictable shape.
- Copy the JSON with ⌥/Alt C or download it with ⌘/Ctrl S. Next actions open it in the JSON Formatter, convert it on to YAML or send it back through JSON to XML.
Examples
Book catalog with attributes
Default settings. Repeated <book> elements become an array, attributes get the @_ prefix, and an element with both an attribute and text puts the text under #text. Values stay strings.
<catalog><book id="bk101"><title>XML Developer's Guide</title><price currency="USD">44.95</price></book><book id="bk102"><title>Midnight Rain</title><price currency="USD">5.95</price><tags/></book></catalog>Result:
{
"catalog": {
"book": [
{
"title": "XML Developer's Guide",
"price": {
"#text": "44.95",
"@_currency": "USD"
},
"@_id": "bk101"
},
{
"title": "Midnight Rain",
"price": {
"#text": "5.95",
"@_currency": "USD"
},
"tags": "",
"@_id": "bk102"
}
]
}
}Same catalog, attributes dropped, values typed
With Attribute prefix set to Drop attributes and Convert numbers & booleans on, the output is closer to what a hand-written JSON API would return.
<catalog><book id="bk101"><title>XML Developer's Guide</title><price currency="USD">44.95</price></book><book id="bk102"><title>Midnight Rain</title><price currency="USD">5.95</price><tags/></book></catalog>Result:
{
"catalog": {
"book": [
{
"title": "XML Developer's Guide",
"price": 44.95
},
{
"title": "Midnight Rain",
"price": 5.95,
"tags": ""
}
]
}
}Consistent arrays for repeated elements
The first order has two <sku> elements and the second has one. With Repeated elements always arrays on and the @ prefix, both orders get an array, so code can loop over sku without checking its type.
<orders><order id="A-1"><sku>K-1</sku><sku>M-3</sku></order><order id="A-2"><sku>K-7</sku></order></orders>Result:
{
"orders": {
"order": [
{
"sku": [
"K-1",
"M-3"
],
"@id": "A-1"
},
{
"sku": [
"K-7"
],
"@id": "A-2"
}
]
}
}Options explained
- Indent — the whitespace used for each nesting level in the JSON output: 2 spaces, 4 spaces or a tab.
- Attribute prefix — the prefix added to attribute names so they cannot collide with child elements:
@_,@or_, or Drop attributes to leave them out entirely. - Convert numbers & booleans — turns numeric and
true/falsetext in elements and attributes into JSON numbers and booleans; when off, every value stays a string. - Repeated elements always arrays — any element name that repeats somewhere in the document becomes an array everywhere it appears, even where it occurs only once.
Common XML to JSON issues
Sometimes an object, sometimes an array
XML has no arrays, so a single child becomes an object or string and several siblings with the same name become an array. Turn on Repeated elements always arrays so every occurrence of a repeating name has the same shape. An element that appears only once in the whole document still stays a single value.
Leading zeros disappear
With Convert numbers & booleans on, 007 becomes 7 and a ZIP code such as 07302 becomes 7302. Leave the option off when the XML carries codes or identifiers, and convert the fields you need in code.
Text and inline elements get mixed up
Mixed content such as <p>Hello <b>world</b> again</p> does not map cleanly to JSON: the inline element becomes a key, and the surrounding text is joined into #text without its spacing or position. XML to JSON suits data documents, not marked-up prose.
Namespace prefixes in keys
Prefixed names such as soap:Envelope are kept as the key name, and xmlns declarations become attributes. Reference them in code with bracket notation, for example data["soap:Envelope"].
The XML declaration is missing from the output
The <?xml ... ?> declaration and other processing instructions describe the file, not the data, so they are left out of the JSON.
Mismatched or unclosed tags
The input must be well-formed XML. Messages such as "Expected closing tag" or "Unclosed tag" give the line and column. Fix them in the XML Formatter, which reports the same errors.
FAQ
Is it safe to convert SOAP responses containing personal data?
Yes. The conversion happens in your browser inside an isolated frame that blocks network requests, so the XML — including SOAP headers with credentials — never leaves your device and nothing is stored on a server. Settings are remembered on this device; the input is only kept if you turn on "Remember my last input".
Is there a standard way to convert XML to JSON?
No single standard exists, which is why the options matter. The common conventions are a prefix for attributes, #text for text next to attributes, and arrays for repeated elements. The defaults here follow those conventions, and the options let you match whatever shape your code expects.
What happens to CDATA sections?
The content of a CDATA section is treated as ordinary text, so <a><![CDATA[x < y]]></a> becomes "a": "x < y". The CDATA markers are not preserved, because JSON strings need no escaping of < or &.
How do I convert an RSS feed to JSON?
Paste the feed and convert. Channel fields become keys under rss.channel, and several <item> elements become an array. Turn on Repeated elements always arrays so a feed with a single item still produces an array, and keep the default attribute prefix to retain version and enclosure URLs.
Can I convert the JSON back to XML?
Yes, with JSON to XML. Keep the @_ attribute prefix and the #text key, because JSON to XML recognizes them and writes attributes and text back in place. Other prefixes, or dropped attributes, will not round-trip.
Why is whitespace in my text trimmed?
Leading and trailing whitespace around text values is removed, because in most XML it is only indentation. Spaces inside a value are kept. If whitespace at the edges matters, check the original in the XML Formatter, which preserves it.
Related tools
To tidy the XML first, use the XML Formatter. To turn the JSON into a spreadsheet, extract the array of records and convert it to CSV. More converters are listed under data tools.