How to Convert JSON to XML
Enter valid JSON, choose a root name and formatting preference, then run the conversion to produce XML. The output structure depends on whether the input contains objects, arrays, blank text, or `null`.
Enter valid JSON, choose a root name and formatting preference, then run the conversion to produce XML. The output structure depends on whether the input contains objects, arrays, blank text, or null.
What this JSON to XML converter does
JSON to XML converts JSON text into an XML document. It is useful when a system, integration, or document workflow accepts XML but your source data is available as JSON. You can provide a root name and choose whether the resulting document should use readable formatting.
The converter treats JSON structure as XML structure: object members become child elements, and nested objects remain inside the element created for their containing member. This makes the result easier to inspect, but XML element naming and array representation can affect how another system reads the document.
Step-by-step instructions
-
Enter the JSON text in the input area. Use a complete JSON value, such as an object, array, string, number, Boolean, or
null. If you leave the input blank or enter only whitespace, the converter accepts it and returns an empty XML string. -
Set the root name if you need a particular document element. When you do not provide one, the default root name is
root. Choose a name that is suitable for an XML element; unsupported characters are replaced with underscores, and a root name that begins with a digit receives a leading underscore. -
Keep pretty formatting enabled for an indented result, or turn it off when compact output better suits the next step in your workflow. For nonempty, non-null JSON with pretty formatting enabled, the result includes an XML declaration and attempts indentation.
-
Run the conversion and review the result. A JSON object becomes a root element with child elements for its members. For arrays, top-level items and object items are wrapped in
itemelements. Primitive arrays nested under an object use the containing member name for repeated elements, while nested lists reuse the parent tag. -
If the result is unsuccessful, inspect the source for malformed JSON, including missing commas, unmatched braces, invalid quotation marks, or an incomplete value. Correct the input and run the conversion again.
How to read the result
Read the output as a structural translation rather than a promise that the JSON text will look identical. Object keys become XML element names, but keys containing unsupported XML-name characters may appear with underscores, and a key beginning with a digit receives a leading underscore. Text containing special XML characters is escaped during serialization, so the serialized form may display entities instead of the original characters.
Pay particular attention to arrays. The element names depend on where the array occurs, so inspect repeated elements before mapping the result into another application. Also distinguish the three empty-value cases: blank or whitespace-only input produces an empty XML string; JSON null produces a self-closing root element; and nonempty, non-null input can receive the XML declaration when pretty formatting is enabled.
Worked example
A developer needs an XML-shaped record from a small JSON customer object before checking how its nested fields and tags will be represented.
Enter { "customer": { "name": "Maya" }, "tags": ["new", "priority"] }, set the root name to record, leave pretty formatting enabled, and run the conversion.
The result has a chosen outer root element, child elements for the object members, and repeated elements for the array values. If pretty formatting remains enabled, nonempty non-null input also has an XML declaration and attempted indentation.
Limitations
- The XML structure may not preserve every JSON key spelling or array label: unsupported name characters are sanitized, and array element names depend on their position in the data.
Common errors
- Malformed JSON causes an unsuccessful result. Check commas, braces, brackets, quotation marks, and value syntax, then submit the corrected JSON.
FAQ
What root name does the converter use?
Yes. The default root name is root, and you can provide another root name. Unsupported characters are replaced with underscores, while a leading digit receives a leading underscore.
What happens when the input is empty or null?
A blank or whitespace-only input returns an empty XML string. JSON null instead produces a self-closing root element.
Why did my JSON to XML conversion fail?
Malformed JSON produces an unsuccessful result rather than a converted XML document. Correct the JSON syntax and submit it again.