XML ⇄ JSON Converter
Convert XML to JSON and JSON back to XML — attributes preserved with the @ convention. Private and instant, no upload.
Convert XML to JSON and back using the widely-recognised convention: attributes become "@name" keys, element text becomes "#text" when mixed with attributes or children, and repeated sibling elements become arrays — so ordinary documents round-trip cleanly.
How to use XML ⇄ JSON Converter
- Paste XML or a single-root JSON object.
- Press the direction you need.
- Copy the result; conventions are documented below the tool.
Who it is for
Integration developers bridging legacy XML APIs to JSON services, QA engineers comparing payloads, and students learning how the two data models really differ.
How it works
- Attributes ride on the element object with an @ prefix, text content lands in #text only when an element also has children or attributes, and repeated siblings become JSON arrays.
- The reverse direction rebuilds attributes, text, and children back into real XML with a standard declaration.
- Empty elements convert to empty strings — nothing is invented.
What it cannot do
- XML has no native arrays: whether siblings become an array depends on repetition, which is the convention’s rule, not a schema’s.
- Namespaces are preserved in element names but not expanded.
Sample input & output
<catalog><book id="101" lang="en"><title>Clean Code</title><price>34.95</price></book></catalog>
{"catalog":{"book":{"@id":"101","@lang":"en","title":"Clean Code","price":"34.95"}}} — round-trippable back into XML with attributes restored.
Frequently asked questions
What does the @ prefix mean?
It marks data that was an XML attribute rather than a child element — the convention used by many converters, kept visible so nothing is ambiguous.
Why did my two <item> elements become an array but a single one did not?
Repetition decides: two or more siblings become an array, a single sibling becomes a plain value. That is the convention’s rule and it round-trips.
Does it support very deep documents?
As deep as your browser’s stack allows — thousands of levels deep is beyond any practical XML anyway.
Why do JSON-to-XML converters require a single top-level root property?
A valid JSON document can be a multi-key object like {"id": 1, "name": "Ada"} or even a bare top-level array [1, 2, 3], whereas XML 1.0 strictly mandates one single outer document element wrapping everything else. Wrapping your JSON payload inside one root key (such as {"response": ...}) gives the serializer an unambiguous root tag name without inventing synthetic wrapper elements.
When does text content appear directly as a string value versus inside a "#text" key?
When an XML leaf element has neither attributes nor child elements — such as <title>Clean Code</title> — mapping it directly to "title": "Clean Code" keeps the JSON idiomatic and compact. When an element carries both an attribute and inner text — such as <price currency="USD">34.95</price> — the element must become an object to hold "@currency": "USD", so its text lands safely in "#text": "34.95".
Why are numbers and booleans inside XML emitted as JSON strings instead of native numbers?
Unlike JSON, raw XML markup without an attached XSD schema carries no primitive scalar types: <code_zip>02138</code_zip>, <version>1.10</version>, and <id>9007199254740993</id> are all untyped character data. Automatically coercing digits into JSON numbers would silently corrupt leading zeros (2138), trailing decimal zeros (1.1), and 64-bit IDs, so preserving strings guarantees lossless XML-to-JSON-to-XML round trips.
What happens to element ordering and XML comments when converting through JSON?
JSON objects map unordered key-value dictionaries rather than an ordered DOM node sequence. If an XML parent interleaves heterogeneous elements — such as <p/>, <img/>, <p/> — grouping sibling tag names into JSON keys groups both <p> elements into one "p" array ahead of "img", and XML comments are dropped because JSON has no comment syntax.