Choose language

JSON to XML Converter

Convert JSON objects and arrays into well-formed XML. Map keys to elements, handle nested data, and produce markup ready for XML-based systems.

Mehmet Demiray Published Updated
Share
Number of spaces per nesting level

Converting JSON Back to XML

JSON is the common language of modern APIs, but many established systems, document formats, and enterprise services still require XML. A JSON to XML converter bridges that gap by turning keys, values, and arrays into properly nested elements. You keep working in JSON, then produce XML only when a destination demands it.

The basic mapping is direct:

JSON XML
{ "name": "Ada" } <name>Ada</name>

Each key becomes an element name, and its value becomes the element's content. Nested objects turn into nested elements, so the depth of your data carries straight over into the markup. Numbers and booleans are written as text inside the tags, since XML treats all content as character data. If your JSON is messy or invalid, run it through JSON Formatter first so the input parses cleanly before you convert. When you need to go the other direction later, the XML to JSON converter reverses the process, and JSON to CSV Converter handles the spreadsheet case.

How Keys, Values, and Nesting Map

The core rule is simple: a JSON key becomes an XML element, and the value goes inside it. Nested objects become nested elements, so the tree depth carries over exactly.

JSON shape XML result
{ "a": { "b": 1 } } <a><b>1</b></a>
{ "a": "text" } <a>text</a>

String, number, and boolean values are all written as the text between the tags, because XML stores everything as character data. A nested object opens a parent element and places its keys as children, so the tree grows exactly as the JSON nests. This predictable mapping means the XML mirrors your JSON structure one level for one level, which makes the output easy to anticipate. Because XML element names cannot contain spaces or start with a digit, keys that break those rules may need adjusting, which is something to watch for when your JSON keys came from a loose or user-supplied source. A clean, well-named JSON document converts into readable XML with no surprises, so it pays to tidy the keys before you convert.

Turning Arrays Into Repeated Elements

JSON has arrays, but XML has no array type. Instead, XML represents a list by repeating the same element. A converter handles this by emitting one element per array entry, all sharing the parent key name.

JSON XML
{ "item": ["a", "b"] } <item>a</item><item>b</item>

This is the natural XML idiom for a collection, and it round-trips cleanly: converting the XML back to JSON collapses the repeated tags into an array again. Arrays of objects work the same way, with each object producing a full element containing its own children, so a list of records becomes a series of identical parent tags. One thing to note is that an empty array has no natural XML output, so it often produces nothing at all rather than an empty tag. If preserving empty lists matters for your downstream system, check the result and add a placeholder element where needed. Mixed-type arrays, where entries are not all the same shape, can also produce uneven elements worth reviewing.

Producing Well-Formed XML

XML has stricter syntax rules than JSON, and a converter handles them so the output parses cleanly. Every opening tag needs a matching closing tag, the document needs a single root element, and certain characters must be escaped inside text.

Character Escaped as
< &lt;
> &gt;
& &amp;

Because JSON allows several top-level keys but XML allows only one root, a converter often wraps your data in a single root element such as <root> to keep the document valid. Values containing reserved characters are escaped automatically so they do not break the markup, which means you can include text with < or & safely. The result is well-formed XML that any standard parser will accept without complaint. If you plan to validate against a schema, remember that conversion produces structurally valid XML but does not guarantee it matches a specific XSD or DTD, so review the element names and ordering against what the target expects before you send it.

When JSON to XML Conversion Helps

Conversion to XML is most useful when you build in JSON but have to deliver in XML. Many SOAP services, financial messaging formats, document standards, and legacy integrations accept only XML. Rather than authoring that markup by hand, you keep your data in JSON and convert at the boundary.

It also helps when generating XML config or feed files from data your application already holds as objects. Producing them through a converter avoids tag typos and unbalanced elements that are easy to introduce when writing markup by hand. When the integration is two-way, the XML to JSON converter turns incoming XML into JSON, so the same data can flow in both directions without manual rework or retyping. For tabular exports, the CSV converter covers that path. Cleaning your JSON in JSON Formatter before converting gives the tidiest markup, since well-formed input leads to well-formed output. The aim throughout is to let each system receive data in the format it expects while you keep working in whichever shape is most comfortable for you.

The ones we answer the most.

How are JSON arrays represented in XML?

XML has no array type, so a list is represented by repeating the same element once per entry. For example { "item": ["a", "b"] } becomes <item>a</item><item>b</item>. This is the standard XML idiom and it converts cleanly back into an array if you reverse the process.

Why does my XML get wrapped in a root element?

XML requires exactly one root element, but JSON can have several top-level keys. To produce valid markup, a converter wraps your data in a single root such as <root>. This keeps the output well-formed so any standard XML parser will accept it.

What happens to special characters in values?

Characters that have meaning in XML are escaped automatically. The < becomes &lt;, > becomes &gt;, and & becomes &amp;. This prevents text values from breaking the markup and ensures the output stays well-formed.

Do all JSON keys make valid XML element names?

Not always. XML element names cannot contain spaces or start with a digit, while JSON keys can. If your keys break those rules, they may need adjusting before they form valid elements. Clean, well-named keys convert without any issue.

Can I convert the XML back to JSON?

Yes. The XML to JSON converter reverses the process and turns XML back into JSON. This is handy for two-way integrations where data flows in both directions between a JSON application and an XML-based system.

Does conversion guarantee my XML matches a schema?

No. The output is structurally well-formed and will parse correctly, but it is not validated against any specific schema. If the target system enforces an XSD or DTD, review the element names and structure against that schema before sending the data.