JSON to XML Converter
Convert JSON back into valid XML documents with proper nesting.
Convert XML to JSON online instantly. Paste any XML document and get clean, structured JSON: attributes are preserved, nested elements become nested objects, and repeated tags become arrays. Everything runs 100% client-side in your browser, so your data never leaves your device.
XML to JSON is not a symmetric operation, and understanding why saves a lot of confusion. XML has four distinct kinds of node content: attributes, text, child elements, and comments. JSON has exactly two things: keys and values. Four into two does not go, so every converter invents a convention to encode the extra distinctions.
The most widely used convention prefixes attribute names with an @ sign and stores an element's own text under a key such as #text. Both characters are chosen precisely because they cannot appear at the start of an XML element name, so there is no risk of a collision with a real child.
An RSS style feed fragment showing attributes, repeated elements, and mixed content in one document.
XML input
JSON output
Look closely at the two tag values. The first item has an array because it had two tag children. The second has a bare string because it had one. Identical structure in the source produces different types in the output, and that is the single biggest hazard of this conversion.
Nothing in an XML document says whether an element is repeatable. Repeatability lives in the schema, and most documents arrive without one. A converter can only look at what is present, so one occurrence looks like a scalar and two look like a list.
Downstream code then breaks in a way that passes every test on the sample file and fails in production the first time a customer sends a document with only one item. There are three practical defences.
| XML construct | Common JSON representation | Notes |
|---|---|---|
| Attribute | "@name": "value" | Prefix keeps attributes distinct from child elements |
| Text content of a leaf | "element": "value" | Collapsed to a plain value when there is nothing else |
| Text alongside children | "#text": "value" | Needed because the element also has real child keys |
| Repeated elements | Array of values or objects | Only produced when more than one occurrence is seen |
| Empty element | null or empty string | Converters differ, check which one yours emits |
| Self closing with attributes | Object holding only @ keys | No text key at all |
| Comment | Dropped | Rarely preserved, treat comments as lost |
| Processing instruction | Dropped | The XML declaration disappears with it |
| CDATA section | Plain string | The wrapper is transport syntax, not content |
Pretty printed XML is full of whitespace text nodes: the newline and indentation between a parent tag and its first child are, strictly speaking, text content. Converters trim them, which is almost always what you want and is technically lossy for elements where whitespace is significant.
Mixed content is the genuinely awkward case. Document oriented XML lets text and elements interleave freely, and JSON has no way to express interleaving order.
Mixed content that JSON cannot represent faithfully
If your XML is document oriented rather than data oriented, JSON may be the wrong target entirely. Keep the markup as a string and parse it with an HTML or XML aware renderer instead.
Namespaces exist so that two vocabularies can be mixed in one document without their element names colliding. A prefix such as dc: is bound to a URI by an xmlns declaration, and the prefix itself is arbitrary: what identifies the element is the URI it resolves to.
JSON has no namespace mechanism, so converters typically flatten. Either the prefix is kept as part of the key, giving dc:creator as a literal key name, or it is stripped entirely, giving creator. Stripping is tidier and risks collisions if two namespaces use the same local name. The xmlns declarations themselves usually survive as ordinary attributes, so you may see @xmlns:dc in the output.
CDATA sections are simpler than they look. A CDATA block is just a way of writing text that contains angle brackets and ampersands without escaping each one, commonly used for embedded HTML or scripts. It carries no meaning of its own, so in JSON it becomes an ordinary string and the wrapper disappears. If the original CDATA held markup, that markup is now a string inside your JSON and still needs escaping before you insert it into a page.
Converting legacy feeds into modern payloads usually leads somewhere next. See the full converter collection for JSON to XML to go back the other way, JSON to TypeScript to type the result before you consume it, and JSON to CSV when the feed items really wanted to be a spreadsheet all along.
Legacy SOAP services, RSS feeds, sitemaps, configuration files, and enterprise integrations still speak XML, while modern applications and REST APIs expect JSON. This XML to JSON converter translates between the two instantly: paste an XML document and get JSON that mirrors the original structure, with attributes preserved, nesting kept intact, and repeated elements grouped into arrays. The parser flags malformed XML with a clear error rather than guessing, so a missing closing tag is caught immediately. Because the converter is free and runs entirely in your browser, it is safe for API responses, invoices, and any XML payload containing sensitive data.