XML to JSON Converter
Convert XML to JSON online: keep or drop attributes, repeated tags become arrays, numbers stay text unless you choose, and errors show line and column.
How to use XML to JSON
- 1Paste XML into the input box, or open an .xml file.
- 2Choose whether to keep attributes, parse numbers and booleans, and how to handle CDATA.
- 3Copy the JSON or download it as a .json file, or switch Mode to Tree to browse the document instead.
What makes it better
- Mode switch for Format, Minify, Validate, JSON to XML and a Tree view
- Attributes kept with a configurable prefix, or dropped
- Repeated elements become arrays, with an option to array-wrap everything
- Numbers and booleans stay text by default so leading zeros survive
- DTD entities refused: no external entities, no entity expansion
About XML to JSON
XML to JSON parses an XML document and writes it as JSON. Attributes can be kept with a prefix, repeated elements become arrays, and values stay as text unless you ask for numbers and booleans, so IDs such as 007 survive. DOCTYPE entity declarations are refused, which blocks external-entity and billion-laughs attacks, and well-formedness errors show their line and column. Switch to Format, Minify, Validate, the other conversion direction or a Tree view without leaving the page: your text stays in the box.
Common uses
- Read an XML API response or RSS feed as JSON for a JavaScript or Python script.
- Convert a legacy XML export into JSON for import into a modern service.
- Inspect the structure of a large XML file as an indented tree of keys.
- Prepare XML test fixtures as JSON for a unit test.
Example
Input
<?xml version="1.0"?> <catalog> <book id="b1"><title>Dune</title><price>9.99</price></book> <book id="b2"><title>Emma</title><price>7.50</price></book> </catalog>
Result
{
"catalog": {
"book": [
{
"title": "Dune",
"price": "9.99",
"@_id": "b1"
},
{
"title": "Emma",
"price": "7.50",
"@_id": "b2"
}
]
}
}Good to know
- An element that appears once is a single value, but the same element appearing twice becomes an array, so the JSON shape can change with the data. Turn on All elements as arrays for a stable shape.
- Comments, processing instructions and the XML declaration are dropped. Mixed content, text around child elements, is collected under the text node name and loses its position.
- A DOCTYPE with <!ENTITY> declarations is rejected rather than expanded. Remove the internal subset to convert the document. A plain DOCTYPE without entities is accepted and ignored.
XML to JSON FAQ
How do I convert XML to JSON?
Paste the XML into the box and the JSON appears alongside. Elements become keys, repeated elements become arrays, and attributes get the prefix @_ unless you turn them off. Copy the result or download it as a file.
Why are my numbers shown as strings?
XML has no number type, and converting automatically would turn identifiers such as 007 or 0123 into 7 and 123. Values stay text by default. Turn on Parse numbers and booleans if you want 12 and true converted, though leading-zero values stay text even then.
Why is my element sometimes an object and sometimes an array?
The converter makes an array only when a tag repeats inside the same parent. With one occurrence you get a single value. If your code expects a list every time, switch on All elements as arrays so each element is wrapped.
What is the DOCTYPE and entity error?
XML can declare its own entities in a DOCTYPE. Attackers use that for external entities that read files and for nested entities that explode in size. This tool never resolves them, so a document containing entity declarations is refused with its position.
What happens to namespaces and CDATA?
Namespace prefixes stay in the names, so <ns:item> becomes the key ns:item and xmlns declarations appear as attributes. CDATA sections are merged into the element's text by default, or kept under a #cdata key if you choose to separate them.