Convert JSON to XML and XML back to JSON, with attributes, arrays and CDATA handled correctly.
Converted locally in your browser — no uploads.
How do you convert JSON to XML?
Each JSON key becomes an element name and its value becomes the element content, wrapped in a single root element. Arrays produce one repeated element per item. Converting back, repeated sibling tags collapse into an array, attributes become @-prefixed keys and mixed text is stored under #text.
Understanding your result
JSON and XML do not map onto each other perfectly, so every converter has to choose a convention. The widely used approach applied here prefixes attributes with @ and stores mixed content under #text, which keeps the round trip predictable. Two differences are worth knowing: XML has no native array type, so a single-item list converts back as a plain value rather than a one-element array, and XML values are always strings, so a number written in JSON returns as a string. XML also restricts tag names — they cannot start with a digit or contain spaces — so illegal characters in JSON keys are replaced with underscores.
Formula and method
Each JSON key becomes an element name and its value becomes the element content. An array produces one element per item, all sharing the key’s name. Going the other way, repeated sibling tags collapse into an array, attributes are prefixed with @ and mixed text is stored under #text.
Assumptions and limitations
The JSON-to-XML mapping is a convention, not a standard, so another tool may produce different output for the same input. Round trips are not perfectly lossless: single-item arrays return as plain values, all XML values come back as strings, and comments and processing instructions are stripped.
Worked example
A book object with a title, a year and a two-item tags array becomes a <book> element containing <title>, <year> and two <tags> elements. Converting that XML back produces the original object with tags restored as an array.
How to use this tool
- Choose whether you are converting JSON to XML or XML to JSON.
- Paste your document into the box.
- For JSON to XML, name the root element.
- Copy or download the converted result.
Common mistakes to avoid
- Expecting a single-item array to survive the round trip as an array.
- Assuming numbers stay numbers — everything returns from XML as a string.
- Using JSON keys with spaces or leading digits, which are not valid XML tag names.
- Hand-escaping ampersands before converting, which double-escapes them.
About the JSON to XML Converter
This converter maps JSON structures onto XML elements and reads XML back into JSON. Arrays become repeated sibling tags, XML attributes become @-prefixed keys, element text becomes #text where an element has both, and CDATA sections are unwrapped safely.
Who should use this tool
Developers integrating modern JSON APIs with older XML-based systems, SOAP services or RSS feeds.
Benefits
- Works in both directions with a consistent, documented convention.
- Preserves XML attributes rather than silently discarding them.
- Sanitises key names that are not legal XML tag names.
- Escapes reserved characters so the XML is always well-formed.
Practical use cases
- Feeding a JSON API response into a legacy system that only accepts XML.
- Turning an RSS or SOAP response into JSON for a JavaScript front end.
- Inspecting the structure of an unfamiliar XML document as JSON.
- Building XML fixtures for tests from JSON sample data.
Explore all Developer Tools tools
Frequently asked questions
How are XML attributes represented in JSON?
As keys prefixed with @. An element like <item id="7"> becomes {"@id": "7"}, which keeps attributes distinct from child elements.
What happens to repeated XML tags?
They collapse into a JSON array. Two <tags> elements under the same parent become a two-item array named tags.
Is the conversion lossless?
Close, but not exactly. XML comments and processing instructions are stripped, single-item arrays return as plain values, and all XML values come back as strings.
Does it handle CDATA sections?
Yes. CDATA content is unwrapped and escaped, so markup stored inside it is preserved as text rather than parsed as elements.
Why did my JSON key change in the XML?
XML tag names cannot contain spaces or start with a digit. Illegal characters are replaced with underscores so the output stays well-formed.