Convert XML to JSON online, with attributes, repeated elements and text nodes mapped for you.
Paste XML, upload an .xml file or drop one here.
Updates as you type. Copy it or download a .json file.
Converting…
This free XML to JSON converter turns an XML document into formatted JSON while you type. Paste an API response, a SOAP payload, an RSS feed, a pom.xml or an export from an older system, and the JSON appears next to it with the nesting preserved. There is nothing to install and no sign-up, and because the conversion runs in your browser, your XML is never uploaded.
XML and JSON do not map one to one: XML has attributes, mixed text and elements, namespaces and no array type, while JSON has objects, arrays and typed values. The converter follows one predictable set of rules, described below, and lets you adjust the parts that people most often need to change.
.xml file. You can also drag a file onto the editor.data.json.This order has attributes, a repeated item element, a CDATA section, an empty element and a ZIP code with a leading zero. The output below is exactly what the converter produces with its default options.
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1042" status="paid">
<customer>
<name>Ada Lovelace</name>
<zip>02134</zip>
</customer>
<item sku="K-100" qty="2">Keyboard</item>
<item sku="M-200" qty="1">Mouse</item>
<note><![CDATA[Leave at <front desk>]]></note>
<gift/>
</order>{
"order": {
"@_id": "A-1042",
"@_status": "paid",
"customer": {
"name": "Ada Lovelace",
"zip": "02134"
},
"item": [
{
"@_sku": "K-100",
"@_qty": 2,
"#text": "Keyboard"
},
{
"@_sku": "M-200",
"@_qty": 1,
"#text": "Mouse"
}
],
"note": "Leave at <front desk>",
"gift": ""
}
}| XML | JSON output | Notes |
|---|---|---|
<a>text</a> | "a": "text" | An element with only text becomes a plain value. |
<a id="1"/> | "a": { "@_id": 1 } | Attributes get the prefix you choose and come first in the object. |
<a id="1">text</a> | { "@_id": 1, "#text": "text" } | Text next to attributes or child elements moves to #text. |
| Child elements | Nested object | Keys follow the document order of the elements. |
| Repeated sibling elements | Array | Only when the name appears more than once under the same parent. |
<a/> | "a": "" | An empty element is an empty string, not null. |
| CDATA section | String | Treated as ordinary text, characters like < and & kept. |
| Comments, processing instructions, declaration | Dropped | The <?xml ... ?> line and its encoding are not carried over. |
& € | & € | Standard entities and numeric character references are decoded. |
JSON has no attributes, so each one becomes a key on the element's object. A prefix keeps it apart from a child element with the same name. The default @_ is the most common convention for XML to JSON converters, and @, _ or no prefix are also available. With no prefix, an attribute and a child element that share a name would overwrite each other, so the converter stops with an error instead of silently losing one of them.
XML has no array type, so a list is simply an element that repeats. A converter can only see that from the data: one <item> becomes a single value, two become an array. That is why a field can be an object in one response and an array in the next, which breaks code that loops over it. If you consume the JSON from code, tick Always use arrays. Every child element is then wrapped in an array, even when it appears once, so the shape no longer depends on how many items the document happened to contain. The root element and the attributes stay as they are.
An element that has text and also attributes or child elements stores its text under #text. Whitespace around text is trimmed, and whitespace-only text between elements is ignored. Mixed content such as <p>one <b>x</b> two</p> is the one case JSON cannot express well: the text pieces are joined into a single #text value (onetwo) and the position of the b element is lost. Documents like HTML or DocBook that rely on mixed content are better kept as XML.
Namespace prefixes are part of the name, so <inv:warehouse> becomes the key inv:warehouse, and a declaration such as xmlns:inv="..." becomes an attribute like any other. The URIs are not resolved, so two elements with the same local name but different prefixes stay separate keys.
<gift/> and <gift></gift> both become an empty string, because XML cannot tell an empty value from a missing one. An empty element that has attributes becomes an object holding only those attributes. If your schema expects null, replace the empty strings after converting.
Everything in XML is text. With Convert numbers and booleans on, 42, 12.50, true and false become JSON numbers and booleans, in elements and in attributes. Values where that would change the meaning stay strings: ZIP codes and IDs with a leading zero (02134), phone numbers with a leading plus, hexadecimal and exponent notation, and numbers too large for JavaScript to represent exactly. Note that 12.50 becomes 12.5. If you need the original text, such as prices with fixed decimals, untick the option and every value stays a string.
Need to go the other way? The JSON to XML converter builds well-formed XML from JSON, and the YAML to JSON converter and CSV to JSON converter cover two other common sources. Once you have the JSON, the JSON Schema Generator can describe its structure, and the JSON Generator creates sample data for testing.
Paste your XML into the XML Input editor, or upload an .xml file. The JSON appears in the output editor as you type, and a syntax error is reported with its line and column. Copy the result, or click Download to save it as data.json.
Every attribute becomes a key on the element's object, with a prefix so it can be told apart from child elements. The default prefix is @_, so id="7" becomes "@_id": 7. You can switch to @, _ or no prefix in the Attribute prefix menu.
XML has no array type, so a list is just an element that repeats. One <item> becomes a single value, and two or more become an array. Tick Always use arrays to get an array for every child element, which keeps the JSON shape the same whatever the data.
Comments, processing instructions and the <?xml ...?> declaration are dropped. CDATA sections are kept as ordinary text, with the angle brackets and ampersands inside them preserved.
Yes. A value such as 02134 stays the string "02134" even with Convert numbers and booleans on, as do values starting with + (phone numbers), hex values and numbers too long to represent exactly. Untick the option to keep every value a string.
Prefixed names such as inv:warehouse are kept exactly as written, and xmlns declarations are converted like any other attribute. The converter does not resolve namespace URIs.
No. The conversion runs entirely in your browser with JavaScript, so your XML never leaves your device. That makes it safe for feeds, exports and configuration files that contain private data.