XML to JSON converter
Paste an XML document and get JSON. Attributes become keys starting with @, text becomes #text, and repeated elements become arrays. Runs in your browser.
Runs in your browser
Convert XML to JSON
Advertisement
How XML maps to JSON
XML has elements, attributes and text, and JSON has objects, arrays and values. The converter uses these rules:
- The root element becomes the single top-level key of the JSON object.
- Attributes become keys prefixed with
@, for exampleid="1"becomes"@id": "1". - Text inside an element with no child elements becomes the value. Text next to child elements is stored under
#text. - Repeated sibling elements with the same name become an array.
Example
<person id="1"><name>John</name><tag>a</tag><tag>b</tag></person>
{
"person": {
"@id": "1",
"name": "John",
"tag": ["a", "b"]
}
}
Common uses
- Reading an XML API response in JavaScript or Python
- Converting an XML config file into a format your code can load
- Preparing XML test fixtures as JSON for comparison
Questions
No. The conversion runs in your browser, so the XML you paste stays on your device.
Element and attribute names are kept as written in the source, including any prefix such as
ns:name. Namespace URIs are not resolved.The input must be well-formed. Check for an unclosed tag, an unescaped
&, or more than one root element. The status line shows the first problem the parser reports.