A JSON to XML converter saves you from rewriting data by hand when two systems expect different formats. Paste your JSON, press Convert, and this JSON to XML converter produces clean, indented XML that you can copy straight into your project. Switch direction and it turns XML into JSON as well. Attributes, repeated elements, arrays and special characters are all handled for you, and a clear message tells you if the input isn't valid. Everything runs in your browser, so your data never leaves your device.
How to use the JSON to XML converter
- Choose a direction: JSON to XML, or XML to JSON.
- Paste your data into the box.
- Set a root element name if you need one.
- Press Convert.
- Copy the result, or press Convert back to check the round trip.
JSON and XML in brief
JSON, or JavaScript Object Notation, is an open standard data format that uses readable text to store and transmit objects made of name and value pairs, along with arrays. XML, or Extensible Markup Language, is a markup language and file format for storing and transmitting data, and its rules are defined in a specification from the World Wide Web Consortium. Both are text and both can describe nested data, but they aren't the same shape. XML has elements, attributes and text, whereas JSON has objects, arrays, strings, numbers, booleans and null. Any converter therefore has to follow a convention for moving between them.
How the conversion works
| JSON | XML |
|---|---|
| Object key | A child element with that name |
| Array | The same element repeated |
| Key starting with @ | An attribute |
| #text key | The element's text |
| null | An empty element |
A worked example
Take this JSON: {"book":{"@id":7,"title":"Dune","tags":["sci-fi","classic"]}}. Since the object has one top-level key, book becomes the root element. The result is <book id="7"> containing <title>Dune</title>, then <tags>sci-fi</tags> and <tags>classic</tags>, then the closing </book> tag. Convert that XML back and you get the same structure, with the id attribute stored under @id and the repeated tags collected into an array again.
Root elements
An XML document needs exactly one root element, while JSON doesn't have that rule. If your JSON has a single top-level key, the converter uses that key as the root. In all other cases, it wraps your data in an element called root, or in whatever name you type into the root element box. If the top level of your JSON is an array, each item becomes an element named item inside the root.
Names that aren't allowed in XML
JSON keys can be almost anything, but XML tag names have rules. They're case-sensitive, they can't contain spaces or most punctuation, and they can't begin with a hyphen, a dot or a digit. The converter fixes these automatically. A key called "first name" becomes first_name, and a key called "2024" becomes _2024. Special characters in values, such as the ampersand and the less-than sign, are escaped so that the XML stays well-formed.
XML to JSON options
All XML values are text, so the tool has to decide what to do with something like 42. With the number option on, whole numbers, decimals, true and false become real JSON values. Values that would change if treated as numbers, such as a ZIP code like 02134 or the price 1.10, stay as strings. Turn the option off if you'd like every value kept as a string. Repeated elements become arrays, attributes are stored with an @ in front of their names, and comments are left out because JSON has nowhere to put them.
What can be lost in conversion
A few details can't survive the trip. An empty JSON array has no XML equivalent, so it simply disappears. A list with one item comes back from XML as a single value instead of an array, because a lone element looks the same either way. In JSON, the order of an object's keys carries no meaning, and the order of mixed text and elements in XML isn't preserved. If you depend on an exact structure, check the output against the schema that the receiving system expects.
Where this conversion is useful
- Connecting older systems that exchange XML with modern APIs that use JSON.
- Reading configuration files in the format you prefer.
- Preparing feeds for services that accept only XML.
- Testing what an integration will send or receive.
Common mistakes
- Using trailing commas or single quotes. Standard JSON doesn't allow them.
- Leaving a tag unclosed. XML is strict about matching start and end tags.
- Changing the case of a tag. In XML, the start and end tags must match exactly.
Related data tools
Check your data with the JSON formatter and validator, or move between tables and JSON with the CSV to JSON converter and the JSON to CSV converter.
What next
Use this often? Add JSON to XML to your Home screen.
Frequently asked questions
How does the JSON to XML converter work?
It turns each key into an element, repeats elements for arrays, and escapes special characters.
Can it convert XML to JSON?
Yes. Switch the direction at the top of the tool.
How do I create XML attributes?
Start a JSON key with @, and it becomes an attribute of its element.
Why was a tag name changed?
XML names can't contain spaces or begin with a digit, so those characters are replaced.
Is my data uploaded?
No. The conversion runs in your browser.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.