JSON to XML Converter
Convert JSON data to XML. @attributes becomes element attributes, #text becomes text content, and arrays become repeated sibling elements — the reverse of our XML-to-JSON converter, right in your browser.
How this JSON to XML conversion works
JSON and XML both describe structured data, but they do not describe quite the same things. XML has attributes and text content, neither of which exists in JSON. Converting naively therefore always runs into the same two questions: how to express attributes, and how to turn an array back into repeated elements. This tool follows the widely used convention of mapping `@attributes` onto element attributes, `#text` onto text content, and arrays onto sibling elements sharing a name.
For example `{"book": {"@attributes": {"id": "1"}, "#text": "Title"}}` becomes `
How to convert JSON into XML
- Paste the JSON Enter the JSON you want converted, as an object or an array.
- Put anything that should be an attribute in @attributes Collect the keys you want emitted as element attributes inside an `@attributes` object.
- Put text content in #text When an element needs both attributes and a body, place the body value under `#text`.
- Check the result and copy it You get indented XML, ready to paste into a configuration file or an API request.
Tips for getting more out of it
- Put an object under an `@attributes` key and each of its properties becomes an attribute on the converted element.
- Use a `#text` key to hold text content for an element that also has attributes or child elements. A simple element with no attributes can just use a plain string as its value.
- Give the same key an array and each item is output as a repeated sibling element sharing that name.
- A value of `null` produces an empty, self-closing tag (`
`) with no attributes, text, or children. - This tool expects input in the format our "XML to JSON converter" produces (an object keyed by the root element name, with exactly one top-level key).
Where this conversion helps
Sending to an API that only accepts XML
When your data is JSON but the receiving end demands XML — a common situation when integrating with older business systems.
Migrating a configuration format
Useful as a first draft when moving settings written in JSON over to an XML-based tool.
Thinking about XML structure in JSON
Writing deeply nested XML by hand is laborious; assembling it in JSON and converting afterwards is much easier to follow.
Pinning down the convention itself
Trying out how `@attributes` and `#text` are reflected helps you settle the specification for a converter you are writing yourself.
JSON to XML terms explained
- Attribute
- The `id="1"` part of `
`. JSON has no equivalent, so this tool represents it with the special `@attributes` key. - Text content (#text)
- The body of `
Title `. Use `#text` when an element needs to carry both attributes and a body. - Entity reference (escaping)
- Rewriting `&` as `&` and so on. **The ampersand must be converted first, or the `&` inside a newly produced `<` gets escaped a second time.**
- Repeated sibling elements
- XML expresses a list by repeating elements with the same tag name. A JSON array converts back into this shape.
- Root element
- XML requires exactly one element at the top. When the top level of your JSON holds several keys, that needs some thought.
Frequently asked questions
Side Note — What to watch for when converting JSON back into XML
Converting XML to JSON is a bit like compressing information. XML can carry three kinds of information — attributes, text, and child elements — while JSON only has plain key-value pairs, so some convention has to be adopted at conversion time (this tool follows the same four rules: `@attributes`, `#text`, arrays, and null). As long as that convention is followed, converting JSON back into XML is a mechanical, well-defined process — but forcing freely-structured JSON that doesn't follow the convention into XML can leave it unclear what should become an attribute versus an element, and the result may not match what you expected.
In practice, this comes up when a legacy XML API response is converted to JSON for easier processing in JavaScript, then converted back to XML to send to another system — for instance, reshaping a SOAP API response as JSON before sending it back out as a SOAP-style request. In this kind of round trip, keeping the conversion convention consistent matters most; mixing in a tool that uses a different convention partway through can scramble the relationship between attributes and text.
This tool strictly requires exactly one top-level key because that reflects a rule of XML itself — a document must have exactly one root element. If you need to convert JSON with multiple top-level keys, wrap it in a common parent key (e.g. `root`) beforehand, and it will convert cleanly into XML with a single root element.