XML to JSON converter
Turn XML into JSON you can use in code, or JSON into XML, with one clear rule for attributes, text and repeated elements.
How to use it
- Pick XML to JSON or JSON to XML.
- Paste the text or open a file. The result updates as you type.
- Turn on Always use arrays if your code expects a list even when an element appears once.
- Copy or download the result. Switching direction moves the result into the input, so you can convert back.
How XML maps to JSON
The same rules are used in both directions:
| XML | JSON |
|---|---|
<title>Moby-Dick</title> | "title": "Moby-Dick" |
<book id="bk1"> | "book": {"@id": "bk1", …} |
Two or more <book> elements | "book": [ … ] |
| Text next to child elements or attributes | "#text": "…" |
<empty/> | "empty": null |
What is not carried over
Comments, processing instructions and the order of mixed text between elements are not kept, because JSON has nowhere to put them. Namespace prefixes stay part of the name, such as "atom:link". Turning JSON into XML, keys that are not valid XML element names have their invalid characters replaced with _, and you are told when that happens.
Related tools
Questions people ask
Is my file uploaded?
No. It is parsed with your browser’s own XML parser and never sent anywhere.
Why is an element an object in one place and an array in another?
An element that appears once becomes a value, and one that repeats becomes an array. Turn on Always use arrays to make every child element an array.
What happens to numbers?
With Read numbers on, 240 becomes a number and true a boolean. Values with leading zeros or very long integers stay text so they do not change.
What does an XML error message mean?
It comes from your browser’s XML parser and names the line and column of the first problem, often an unclosed tag or an unescaped &.