How to convert XML to JSON
- Paste XML into the editor, or load a file.
- Click Convert to JSON. If the XML isn't well-formed, click Format to see exactly where, and Repair to close unclosed tags and fix common mistakes.
- Copy or download the JSON from the result panel.
How XML maps to JSON
| XML | JSON |
|---|---|
| The root element | Its contents become the top-level object |
<name>Ada</name> | "name": "Ada" |
Attributes <user id="7"> | Keys next to the child elements: "id": "7" |
| Repeated elements with the same name | An array |
| Nested elements | Nested objects |
Text next to attributes <price currency="EUR">9.5</price> | {"currency": "EUR", "": "9.5"} |
For example:
<order id="17"> <item>Pen</item> <item>Book</item> </order>
becomes {"id": "17", "item": ["Pen", "Book"]}.
Things to know
- All values are strings. XML text has no types, so
<qty>2</qty>becomes"2". Convert types in your code, or generate typed classes with the Object Mapper. - A single element is not an array. If an element appears once, it becomes a value, not a one-item array. Code that reads the JSON should accept both.
- To go the other way, use the JSON to XML converter.
Conversion runs on our server in memory; the data isn't stored.
Frequently asked questions
How are XML attributes converted?
Attributes become ordinary keys in the JSON object, next to the child elements, without a prefix. For <user id="7"><name>Ada</name></user> you get {"id": "7", "name": "Ada"}.
Why are my numbers strings in the JSON?
XML stores everything as text and doesn't say whether 42 is a number or a string, so the converter keeps values as strings. Convert them where you use the data.
How are repeated elements handled?
Elements with the same name under the same parent become a JSON array. An element that appears only once becomes a single value.
What happens to the root element?
Its name is dropped and its attributes and children become the top-level JSON object.
Is my XML stored?
No. It's converted on our server in memory and sent straight back.