JSON to XML Converter
Convert JSON to XML and XML to JSON in your browser, with attributes, repeated elements and CDATA handled. Nothing is uploaded to a server.
How to use the JSON to XML converter
- Choose the direction: JSON → XML or XML → JSON.
- Paste your data, or click Open a file to load a
.jsonor.xmlfile (up to 10 MB). - Set the options: Indentation (2 spaces, 4 spaces, tab or None (compact)) for both directions; Root element and Add the XML declaration for JSON → XML; Convert numbers and booleans for XML → JSON.
- Click Convert. The result also updates while you type, and errors show the line and column where the problem was found.
- Copy or download the result. Swap direction puts the output back into the input so you can check the round trip.
How JSON maps to XML
XML and JSON do not have the same data model, so every converter follows a convention. This tool uses the widely used one from the fast-xml-parser library:
| JSON | XML |
|---|---|
{"title": "Dune"} |
<title>Dune</title> |
{"book": {"@id": "42"}} |
<book id="42"/> |
{"p": {"@lang": "en", "#text": "Hi"}} |
<p lang="en">Hi</p> |
{"tag": ["a", "b"]} |
<tag>a</tag><tag>b</tag> |
- Keys that start with
@become attributes, and the key#textholds the text of an element that also has attributes. - An array becomes a repeated element with the same name.
- An XML document needs exactly one root element. If your JSON is an object with a single key whose value is an object, that key becomes the root. Otherwise, the whole value is wrapped in the element named in Root element (
rootby default), and top-level array items become<item>elements. - Keys that are not valid XML names are fixed: spaces and symbols become
_, and a name that starts with a digit gets a leading_("1st place"→<_1st_place>). nulland empty strings give an empty element such as<note/>. Special characters (&,<,>, quotes) are escaped.
How XML maps to JSON
- Attributes become keys prefixed with
@, and mixed text becomes#text. - Repeated elements become an array; an element that appears once becomes a single value.
- CDATA sections are merged into the text, and entities such as
&are decoded. The XML declaration, processing instructions and comments are dropped. - With Convert numbers and booleans,
<price>12.5</price>becomes12.5andtruebecomes a boolean, while values with a leading zero, such as007, stay strings. Turn the option off to keep every value as text.
Before converting, the XML is checked for well-formedness: a missing closing tag, a mismatched tag or an unescaped & is reported with its line and column.
Frequently asked questions
Is my data sent to a server?
No. The conversion runs entirely in your browser. Your XML feeds, SOAP messages and configuration files stay on your computer.
Why does an element become an array in one file and an object in another?
XML does not say whether an element is a list. When <tag> appears twice, it becomes an array; when it appears once, it is a single value. If your code expects an array, handle both cases, or add a second element when testing.
Why is the round trip not always identical?
Some information has no equivalent on the other side: comments, the order of mixed content, or the difference between a one-element array and a single value. For typical data documents, converting JSON → XML → JSON gives the same structure back.
Can I use namespaces?
Yes. Prefixed names such as soap:Envelope and attributes such as @xmlns:soap are kept as they are in both directions.
Does it validate against an XSD schema?
No. It checks that the XML is well-formed, but it does not validate it against a DTD or an XSD schema.
Related tools
- JSON Formatter and Validator Free JSON formatter and validator that beautifies, minifies and checks JSON in your browser, with syntax errors reported by line and column.
- JSON to YAML Converter Convert JSON to YAML and YAML to JSON in your browser, with anchors, merge keys and multi-document files supported. Nothing is uploaded.
- JSON to CSV Converter Convert JSON to CSV and CSV back to JSON in your browser. Nested keys are flattened into columns, delimiters are detected, and nothing is uploaded.