XML to JSON converter
Paste XML from a web service or an export file to get JSON that is easy to use in JavaScript and modern APIs.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter xml text, turn numbers and true/false into typed values and indentation.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
The XML is parsed by a built-in well-formedness checking parser. A text-only element becomes a string, an attribute becomes an @key, text next to child elements or attributes becomes #text, and same-name siblings become an array. Comments and processing instructions are dropped.
Example
Inputs: Turn numbers and true/false into typed values = no, Indentation = 2 spaces. Result: JSON: { "catalog": { "book": [ { "@id": "1", "@lang": "ar", "title": "مقدمة ابن خلدون", "author": "ابن خلدون", "price": "45" }, { "@id": "2", "@lang": "en", "title": "Arabian Sands", "author": "Wilfred Thesiger", "price": "60" } ] } }; Root element: catalog; Elements: 9.
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="1" lang="ar">
<title>مقدمة ابن خلدون</title>
<author>ابن خلدون</author>
<price>45</price>
</book>
<book id="2" lang="en">
<title>Arabian Sands</title>
<author>Wilfred Thesiger</author>
<price>60</price>
</book>
</catalog>{
"catalog": {
"book": [
{
"@id": "1",
"@lang": "ar",
"title": "مقدمة ابن خلدون",
"author": "ابن خلدون",
"price": "45"
},
{
"@id": "2",
"@lang": "en",
"title": "Arabian Sands",
"author": "Wilfred Thesiger",
"price": "60"
}
]
}
}Limits and caveats
- Mixed text between child elements is joined into one #text key, so its position is lost.
- Entities declared inside a DOCTYPE are not supported, only the five standard ones and numeric references.
- Namespace prefixes such as ns:tag stay part of the key name.
Questions about this tool
Why are some elements arrays and others not?
An element that repeats under the same parent becomes an array, one that appears once stays a single value, which is how most converters work.
What do @ and #text mean?
A key starting with @ is a tag attribute such as id, and #text is the element text when the element also has attributes or children.
Do numbers stay as strings?
Yes by default, so values like 007 or 2.50 never change. Turn on typed values to make plain numbers, true and false real JSON types.
