JSON to XML
Convert JSON to XML with attribute support, arrays and indentation control.
Runs in your browser — your data never leaves your deviceFree, no sign-up
XML output
The converted XML will appear here.
How it works
The input is first parsed as JSON with precise error reporting. The value is then serialized as XML using the fast-xml-parser library — a real, widely used XML implementation: nested objects become elements, arrays become repeated elements, and @-prefixed keys become attributes.
The generated XML is validated before it is shown, so illegal element names surface as errors rather than broken output.
Features
- Attribute and text-node support (@keys and #text)
- Arrays as repeated elements
- Sensible root element handling, wrapping when needed
- Optional XML declaration, 2 or 4 space indentation
- Output validated — JSON errors reported with line/column
- 100% client-side — nothing leaves your browser
How to use
- Paste JSON, or upload a .json file.
- Choose indentation and whether to include the
<?xml?>declaration. - Press Convert to XML, then copy the result or download it as a .xml file.
Example
JSON:
{"deployment": {"name": "app", "replicas": 4}}
XML:
<deployment>
<name>app</name>
<replicas>4</replicas>
</deployment>Frequently asked questions
- How does the converter decide on the root element?
- XML requires exactly one root element. If your JSON is an object with a single key whose value is not an array, that key becomes the root: {"deployment": {…}} becomes <deployment>…</deployment>. Any other object is wrapped in a <root> element, and a top-level array becomes repeated <item> elements inside <root> — XML has no bare top-level array.
- How do I create XML attributes?
- Use keys starting with @ in your JSON, and #text for an element's text content. For example, {"a": {"@_id": "1", "#text": "hi"}} produces <a id="1">hi</a>. This is the standard convention used by the underlying fast-xml-parser library.
- What happens to arrays?
- Arrays become repeated elements: {"ports": [8080, 8443]} produces <ports>8080</ports><ports>8443</ports>. Note the asymmetry when converting back: a single-element array produces one element, which parses back as a plain value rather than an array.
- Is the generated XML validated?
- Yes. The output is run through an XML validator before you see it, so JSON keys that are not legal XML element names (containing spaces, "<", or starting with a digit) produce a clear error instead of silently broken XML.
- What happens if my JSON is invalid?
- You get a clear error message with the line and column where the JSON parser failed. Nothing is converted until the input parses.
- Is my data sent to a server?
- No. Conversion happens entirely in your browser with JavaScript. Nothing you type or paste is transmitted anywhere — you can verify this in your browser's network inspector.