๐ XMLโJSON Converter
Couldn't convert this โ please check the input format.
Convert XML data into JSON, or JSON into XML. Useful for converting between data formats for API integration, or inspecting the contents of a legacy XML config file. Attributes are represented as "@attributeName" and text nodes as "#text".
How to use
- Choose the direction: "XML โ JSON" or "JSON โ XML".
- Paste the data you want to convert into the input box.
- The converted result appears automatically below. Use the "Copy" button to copy it.
How the calculation works
XML represents hierarchy by nesting tagged elements. Converting to JSON maps elements to object keys and child elements to nested objects. Some XML features have no direct JSON equivalent. This tool represents attributes with an "@name" key and an element's text content with "#text": <person id="1">Taro</person> becomes {"person": {"@id": "1", "#text": "Taro"}}. That notation is a convention shared by many XMLโJSON libraries. XML also allows several child elements with the same name, but a JSON object cannot repeat a key, so repeated elements are gathered into a JSON array.
Worked example
Converting this XML <books> <book id="1">I Am a Cat</book> <book id="2">Botchan</book> </books> results in {"books": {"book": [ {"@id": "1", "#text": "I Am a Cat"}, {"@id": "2", "#text": "Botchan"} ]}} There are two <book> elements, so they become an array, with each id attribute represented as "@id".
Things to be aware of
- A single child element becomes an object, not an array, so the JSON shape can change with the number of elements.
- Namespace (xmlns) handling is basic; documents with complex namespaces may not convert as expected.
- XML comments and processing instructions (<?xml ...?>) are not included in the output.
- An element with only text and no attributes becomes a plain string rather than an object: <name>Taro</name> becomes "name": "Taro". Attribute values and text are all treated as strings.
FAQ
How are XML attributes represented?
Attributes appear as a key prefixed with "@" โ for example, the id in <person id="1"> becomes "@id": "1".
What happens with multiple child elements sharing the same tag name?
When a tag name appears more than once at the same level, it's collected into a JSON array.
Does this handle XML namespaces (xmlns)?
Basic XML structure is supported, but namespace handling is simplified. Complex namespaced documents may not convert exactly as expected.