XML to JSON Converter
Turn XML into JSON with predictable rules, so the result is easy to use in JavaScript, Python or any API.
or drop a file here · .xml, .txt · up to 20 MB
About the XML to JSON Converter
Many older services and accounting packages still speak XML, while modern code expects JSON. This converter uses a small set of fixed rules, so the shape of the output is predictable.
The mapping rules
- The root element becomes the single top-level key.
- Each attribute becomes a key with an @ in front, for example “@id”.
- An element with only text and no attributes becomes a plain string.
- When an element has attributes and text, the text is stored under “#text”.
- A child element that appears more than once under one parent becomes an array; one that appears once stays a single value.
- CDATA becomes ordinary text. Entities such as
&are decoded to the character they stand for. - Comments, processing instructions and the DOCTYPE are dropped, since JSON cannot hold them.
Worked example
Select Try an example and then Convert to JSON. The catalogue becomes an object with a “catalog” key holding a “book” array of two objects. The first book has “@id”: “b1” and “@lang”: “en”, a “title” string, a “price” object with “@currency”: “INR” and “#text”: “499”, and a “tags” object whose “tag” value is a two-item array.
Now tick Convert numbers and true/false and convert again. The price text becomes the number 499. Values like “007” or a 20-digit account number are left as text, because turning them into numbers would lose leading zeros or precision.
Things to watch
- One versus many: if a feed sometimes has one item and sometimes several, the item is an object in the first case and an array in the second. Code that reads the result should accept both.
- Text in mixed content, such as a sentence with a bold word inside it, is joined and trimmed, so formatting inside paragraphs is lost.
- Input that is not well-formed is refused; the XML validator helps you find the fault.
- To reverse the process, use JSON to XML, which follows the same @ and #text conventions.
How to use XML to JSON Converter
- Paste XML or open an .xml file.
- Choose the indentation and whether to convert numbers and true/false.
- Select Convert to JSON, check the result, then copy or download it.
Privacy: how it works
Everything happens in your browser. Your text is not sent to any server.
Frequently asked questions
How are attributes and text stored?
Attributes become keys starting with @, such as "@id". An element that only has text becomes a plain string. If an element has both attributes and text, the text goes under "#text".
Why is one element an array and another a single object?
An element that appears more than once under the same parent becomes an array. If it appears once it stays a single value, because XML itself does not say whether a list was meant.
Are comments and the DOCTYPE kept?
No. JSON has no place for them, so comments, processing instructions and the DOCTYPE are left out. CDATA content is kept as ordinary text.