XML to JSON Converter
Convert XML to JSON as you type.
How to convert XML to JSON
- Paste an XML document into the left box. The JSON appears on the right as you type.
- Keep Detect numbers, booleans and null ticked to turn values like
42andtrueinto JSON types, or untick it to keep all text as strings. - Choose the JSON indent, then copy the result or select Download to save
converted.json. - Use Swap to go back to XML with the JSON to XML converter.
The XML is checked first, and a malformed document, such as a missing closing tag, is reported with its line and column. Parsing happens in your browser; your XML is never uploaded.
Example
This XML:
<book id="bk101">
<title>XML Basics</title>
<author>Ada</author>
<author>Alan</author>
<price>29.99</price>
</book>becomes this JSON:
{
"book": {
"title": "XML Basics",
"author": [
"Ada",
"Alan"
],
"price": 29.99,
"@_id": "bk101"
}
}Frequently asked questions
How are attributes represented?
Attributes become keys prefixed with @_, so id="bk101" turns into"@_id": "bk101". When an element has both attributes and text, the text is stored under#text. The prefix keeps attributes apart from child elements with the same name.
When does an element become an array?
An element that appears more than once under the same parent, like the two <author> elements above, becomes an array. An element that appears once becomes a single value, so check for both shapes if your code reads documents where the count varies.
What happens to comments, CDATA and the XML declaration?
Comments, processing instructions and the <?xml ?> declaration are left out. CDATA sections and entities such as & are decoded into plain text. Values with leading zeros, like007, stay strings.