XML to JSON Converter
Convert an XML document, RSS feed, GPX track or any XML file into JSON, with attributes, repeated elements and text mapped the usual way.
Results
What this tool does
XML and JSON describe the same kind of tree, but XML has things JSON lacks, so every converter has to pick a convention. This one uses the most common: attributes become keys starting with @, repeated elements with the same name become a list, an element that only holds text becomes that text, and text sitting next to child elements goes under #text. By default every value stays a string, which is the only lossless choice, because XML cannot say whether 007 is a number; switch to typed values if you want numbers and true/false as JSON values. Comments and the <?xml?> declaration are dropped, and namespace prefixes are kept as part of the names.
Formula
attribute → "@name" ; text beside children → "#text" ; children with the same name → list ; empty element → null
Variables
| Symbol | Meaning | Unit |
|---|---|---|
text | XML | — |
types | Values | — |
indent | Spaces of indentation | — |
OUT | JSON | — |
EL | Elements read | — |
AT | Attributes | — |
DP | Nesting depth | — |
Worked example
- XML<?xml version="1.0" encoding="UTF-8"?> <library name="City"> <book id="1" available="true"> <title>Dom Casmurro</title> <year>1899</year> </book> <book id="2" available="false"> <title>Os Maias</title> <year>1888</year> </book> <link>https://example.org</link> </library>
- Values0
- Spaces of indentation2
- JSON{ "library": { "@name": "City", "book": [ { "@id": "1", "@available": "true", "title": "Dom Casmurro", "year": "1899" }, { "@id": "2", "@available": "false", "title": "Os Maias", "year": "1888" } ], "link": "https://example.org" } }
- Elements read8
- Attributes5
- Nesting depth3
Limitations
- The calculation runs entirely in your browser. The values you type are never sent to a server.