JSON and XML look like cousins: both are text, both nest data inside data, both move records. So it is natural to assume converting one to the other is a formatting change, the same data in different brackets. It is not. The two formats disagree about basics: what a value is, how a list is written, and where a small fact like an ID is allowed to live.
The JSON to XML Converter on Ovatly applies a deterministic mapping: the same input always produces the same output. But deterministic is not the same as identical. This guide walks through each change, so you can read the output and know why it looks the way it does.
Contents
- Quick answer
- Types flatten: everything becomes text
- Null becomes an empty element
- Arrays become repeated siblings
- Attributes are opt-in, with @ keys
- Names get repaired when XML would reject them
- How to convert JSON to XML, step by step
- Worked example: one record, before and after
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Four things change when JSON data moves to XML. Types disappear: numbers and booleans become plain element text, and null becomes an empty element. Arrays unfold: each item becomes its own repeated element instead of staying a list. Attributes appear only where you asked for them, on keys that start with @. And order survives: keys become elements in their JSON sequence. Paste your JSON into the JSON to XML Converter, choose a root element name, and download converted.xml to see each change on your own data.
Types flatten: everything becomes text
JSON has six value types: objects, arrays, strings, numbers, booleans and null. XML has one: text inside elements. So the moment a value crosses over, its type is lost. A price stored as the number 12.5 arrives as the text 12.5 between two tags. A flag stored as true arrives as the word true. Nothing in the XML says these were ever a number or a boolean.
This matters when the receiving system reads the file back: it must parse the text and decide the type, guided by its own schema or code. If your JSON distinguishes between the number 7 and the string "7", that distinction does not survive the trip: both become the text 7. Treat the XML as a text document a reader interprets, not as a typed snapshot.
Null becomes an empty element
JSON can say a field exists but has no value: null. XML has no null, so the converter writes the field as an element with nothing inside it. A missing key and a null key therefore look different in the output: a missing key produces no element at all, while a null key produces an empty one.
A system reading the XML can therefore tell "the record mentioned this field and it was empty" apart from "the record never mentioned this field", but only if it treats an empty element as meaningful. If your data uses null loosely, decide before converting whether those nulls should stay as empty elements or be dropped from the JSON first.
Arrays become repeated siblings
An array groups repeated items under one key. XML has no array syntax, so the converter repeats the element instead: one element per item, all siblings, all with the same name. A list of two tags becomes two <tag> elements in a row.
The information survives, but the shape changes. Code reading the XML cannot ask for "the array"; it collects every sibling with the matching name and builds the list itself. An array of objects becomes a run of repeated elements, each holding its own children.
Attributes are opt-in, with @ keys
XML gives each element two places to put facts: child elements, and attributes, the name-and-value pairs inside the opening tag. JSON has only one place: keys. The converter bridges this with a naming rule: a key starting with @ becomes an attribute on the parent element, with the @ dropped. Every other key becomes a child element.
So @id lands as an attribute, while a plain id key lands as a child element. They are different XML, and a receiving system written for one will not find the value in the other. Choose deliberately: attributes suit short identifying values, and elements suit everything else, especially anything that might later need children of its own.
Names get repaired when XML would reject them
XML element names follow stricter rules than JSON keys: a JSON key can contain spaces or start with a digit, and an XML name cannot. Rather than fail the conversion, the converter repairs problem names: invalid characters are replaced with underscores, and a digit-leading key gets an underscore prefix.
Repairs keep the conversion running, but the output name may not match the input key exactly. If a downstream system looks elements up by name, check the output for repaired names and fix the keys in your JSON first if the exact spelling matters. Special characters inside values are escaped instead, so a value containing an ampersand stays valid XML and reads back as the original characters.
How to convert JSON to XML, step by step
- Open the JSON to XML Converter and paste your JSON. The conversion runs in your browser, so nothing is uploaded.
- Choose the root element name: the one element that wraps everything else.
- Check the preview: types as text, arrays repeated,
@keys as attributes. - Download converted.xml, and keep the original JSON: the XML cannot be turned back into the same typed data.
Worked example: one record, before and after
Here is a small record, the converter's own entry example:
{"person":{"@id":"7","name":"Ana","tag":["a","b"]}}
Converted, it becomes:
<person id="7">
<name>Ana</name>
<tag>a</tag>
<tag>b</tag>
</person>
Read it against the rules. The person key becomes the root element. The @id key becomes the attribute id="7" on that element, not a child. The name key becomes a child element holding text. The tag array becomes two <tag> elements as siblings. Nothing was added and nothing was dropped, but the tree shape is different from the JSON shape.
Now add types to the same pattern:
{"item":{"price":25,"inStock":true,"note":null}}
<item>
<price>25</price>
<inStock>true</inStock>
<note/>
</item>
The number 25 and the boolean true are now just text, and null has become the empty <note/> element. Same data, flatter world.
Limitations and honest tradeoffs
The converter produces one consistent dialect of XML: the same rules applied every time. That predictability is the point, but the output is not tailored to any system's schema. A system expecting its own element names and attribute choices may need the output adjusted before it accepts it.
The deeper limit is the formats themselves: XML cannot carry JSON types, so a round trip back to JSON cannot restore them without outside knowledge. Convert in one direction, for a reader that expects XML, and keep the JSON as the typed source of truth.
Common mistakes
- Expecting the XML to mirror the JSON shape. Arrays repeat and types flatten; sketch the expected output with those rules first.
- Writing id as a plain key and looking for an attribute. Only
@keys become attributes. A plain key becomes a child element. - Assuming null and missing are the same. Null produces an empty element; a missing key produces nothing.
- Ignoring repaired names. Keys with spaces or leading digits come out with underscores; check output names if a reader looks elements up by name.
- Treating the output as schema-perfect. The dialect is consistent, not custom; compare it with the receiving system's expectations first.
FAQs
Does XML keep JSON data types? No. XML has no native number, boolean or null types, so the number 250 becomes the text 250 inside an element, true becomes the text true, and null becomes an empty element.
What happens to a JSON array in XML? Each item becomes its own element with the same name, repeated as siblings. A tag list of a and b becomes two tag elements, one holding a and one holding b.
How do I get an XML attribute instead of an element? Prefix the key with @ in the JSON. A key named @id becomes the attribute id on the parent element, while a plain id key becomes a child element.
Is the order of my data preserved? Yes. The converter walks the JSON in order, so elements appear in the XML in the same order as the keys in the object.
Is my JSON uploaded to a server during conversion? No. The converter runs fully in your browser, so your data never leaves your device during conversion.
Conclusion
Moving data from JSON to XML is a translation with fixed rules: types flatten to text, null empties out, arrays repeat as siblings, attributes appear only where an @ key asks for them. Know the rules and the output stops being a surprise: it becomes something you can design for. When the feed you are building is a product catalogue rather than a single record, our guide to converting JSON product data to XML for a marketplace feed applies the same mapping at catalogue scale. For more guides in this series, see our Data and JSON Tools guides.
References
- W3C, Extensible Markup Language (XML) specification, on element and attribute structure: https://www.w3.org/TR/xml/
- MDN Web Docs, on the JSON data format and its value types: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON