Convert JSON to XML with full control over attributes and arrays
The JSON to XML converter turns API responses, configuration objects and exported records into well-formed XML for SOAP services, product feeds, Android resources, XSLT pipelines and older systems that only accept XML. Paste JSON or open a .json file and the XML updates as you type, indented the way you like.
JSON and XML are not shaped the same: XML has attributes, element text and repeated elements, and its element names cannot contain spaces or begin with a digit. This converter follows the convention most libraries use — keys that start with @ become attributes and #text becomes the element’s text — and lets you change every rule. Keys that are not legal XML names are repaired, and each result is parsed again by your browser’s own XML parser before you see it.
The conversion happens on your device. Nothing you paste is uploaded, and very large numbers such as 64-bit IDs keep every digit.
How to use the JSON to XML Converter
- Paste JSON into JSON input, drop a file onto the box or press Open file. Invalid JSON is reported with its line and column and a Go to error button.
- Set the Root element and Array item element. With “Use a single top-level key as the root” ticked,
{"catalog": {…}}becomes<catalog>instead of being wrapped. - Tell the converter how your JSON marks attributes — keys with a prefix such as
@, or one_attributesobject — and which key holds element text. - Choose how arrays,
nullvalues and invalid names are written, the indent, and whether to include the XML declaration. - Press Copy or Download XML. Swap opens the result in the XML to JSON converter with the same settings, so you can check the round trip.
JSON to XML Converter features
Attributes, text, CDATA and comments
"@id": 7 becomes id="7", #text becomes element text, #cdata is written as a CDATA section (any ]]> inside is split safely) and #comment as an XML comment.
Arrays your way
Repeat the element once per item — <tag>a</tag><tag>b</tag> — or wrap the items inside it. Top-level arrays and lists inside lists use the array item element you name.
Legal element names
Spaces, slashes and leading digits are not allowed in XML names. Replace them with underscores (page size → page_size) or encode them reversibly as _x0020_, the escape SQL Server and .NET use.
Correct escaping
&, < and > are escaped in text; quotes, tabs and line breaks in attribute values; control characters that XML 1.0 cannot store are removed with a warning.
Ordered node lists
The ordered format written by the XML to JSON converter’s “Preserve element order” option is recognised and rebuilt exactly, mixed text included.
Namespace-aware
A prefixed key such as media:thumbnail is kept when a matching @xmlns:media declaration is in scope; otherwise the colon is replaced so the output stays valid.
How JSON maps to XML
Numbers and booleans become plain text, because XML itself has no data types — those live in an XML Schema (XSD). When you convert back with XML to JSON, tick “Convert numbers & booleans” to get them back. XML allows exactly one root element, so JSON with several top-level keys is wrapped in the root element you name.
| JSON | XML with the default settings |
|---|---|
{"book": {"title": "Dune"}} | <book><title>Dune</title></book> |
"@id": "b1" | the attribute id="b1" |
"price": {"@currency": "INR", "#text": 499} | <price currency="INR">499</price> |
"tag": ["a", "b"] | <tag>a</tag><tag>b</tag> |
[1, 2] as the whole document | <root><item>1</item><item>2</item></root> |
"note": null | <note/>, <note xsi:nil="true"/> or nothing |
"page size": "A5" | <page_size>A5</page_size> |
Matching the JSON style your tools expect
Different libraries write XML-shaped JSON in different ways. Set the attribute and text options to match the data you have:
- @ and #text — the default here and in many converters. fast-xml-parser uses
@_as its default prefix: type@_into Attribute prefix. - BadgerFish — attributes are
@nameand element text is$: set Text node key to$. - xml-js compact — attributes sit in an
_attributesobject and text under_text: choose “_attributes object” and set Text node key to_text. - Plain objects — JSON without any markers is fine; every key becomes a child element and no attributes are produced.
Problems this converter fixes for you
To tidy or validate the JSON first, use the JSON Formatter; to check or pretty-print the XML afterwards, use the XML Formatter.
- Invalid names. Keys like
first name,2024ora/bwould make broken XML. They are repaired, and a badge shows how many names changed. - Undeclared prefixes.
m:xwithout anxmlns:mdeclaration is not namespace-well-formed, so it is written asm_x. - Precision loss. JavaScript rounds 12345678901234567890 to 12345678901234567000; this tool reads the original digits instead (and keeps
1.50as written). - Empty arrays. XML has no empty list, so
"list": []becomes<list/>and the key is not silently lost.
JSON to XML Converter FAQ
How do I convert JSON to XML?
Paste your JSON into the input box. The JSON to XML conversion runs immediately; adjust the root element, attribute prefix and indent if needed, then copy the XML or download it as an .xml file.
How do I create XML attributes from JSON?
Start the key with @. {"book": {"@id": "b1", "title": "Dune"}} becomes <book id="b1"><title>Dune</title></book>. If your JSON keeps attributes in an _attributes object, choose that option under “Attributes from”.
What happens to JSON arrays?
By default each item becomes its own element with the array’s key as its name, which is how XML normally represents lists. Choose “Wrap items in the element” to get <tags><item>…</item></tags> instead; the item name is yours to set.
Why were some of my keys renamed?
XML element names cannot contain spaces or most punctuation and cannot start with a digit or hyphen. Invalid characters are replaced with underscores, or encoded as _xHHHH_ if you pick that option, which XML to JSON can decode back to the original key.
Can I convert the XML back to the same JSON?
Yes. Press Swap and the XML opens in the XML to JSON converter with matching settings. Values come back as text unless numbers and booleans are converted, and an array with one item comes back as a single value unless you list its name as always-array.
Is my JSON uploaded anywhere?
No. Parsing and conversion run entirely in your browser, so API keys, customer records and internal configuration never leave your device.