100% local

JSON to XML Converter

data_object JSON Input
task_alt XML Output

JSON to XML Converter

Convert JSON into a well formed XML document for SOAP endpoints, legacy integrations, and tools that still expect angle brackets. Keys become elements and array items become repeated siblings.

JSON and XML describe overlapping but not identical things, so this conversion involves real decisions rather than a mechanical substitution. XML has attributes, namespaces, comments, processing instructions, and mixed content, none of which JSON has. JSON has arrays and a distinction between a number and a string, neither of which XML has. Every JSON to XML converter picks a convention, and knowing which one you are using is the difference between output that works and output that almost works.

The convention here is the simplest defensible one. Every key becomes an element, never an attribute. Array items repeat the element name of the key that held them. A null value and an empty object both become a self closing element. The document is wrapped in a single root element and prefixed with an XML declaration, so what you copy out is a complete, parseable document rather than a fragment.

Element names, and the two cases that would otherwise produce invalid XML

XML element names are far more restrictive than JSON keys. A JSON key can be any string at all, including an empty one, while an XML name may only contain letters, digits, hyphens, underscores, and periods, and may not begin with a digit or a hyphen. A key like my key or a.b therefore cannot be used directly, and the converter replaces the characters XML rejects with underscores, giving my_key and a_b.

Character replacement alone is not enough, because a key such as 2nd survives it unchanged and still cannot start an element name. Such names get an underscore prefix, so 2nd becomes _2nd. This matters because the alternative is output that looks fine, copies cleanly, and then fails at the first parse on the other side, which is a considerably worse outcome than a slightly ugly name.

The second invalid case is a top level array. XML permits exactly one root element, so mapping an array of two records straight through would produce two sibling roots and an unparseable document. A top level array is therefore wrapped in a single root element with each entry written as an item element. Arrays nested under a key keep the repeated sibling convention, because there the parent element already provides the required single container.

How JSON constructs map to XML

Each row is a real input fragment and the exact markup this tool emits.

JSONXML outputNotes
{"id":42}<id>42</id>An object key becomes an element containing the value.
{"tags":["a","b"]}<tags>a</tags> <tags>b</tags>Array items repeat the element name of the key that held them.
{"x":null}<x />Null becomes a self closing element. An empty object and an empty array produce the same thing.
{"n":"Ada & Co"}<n>Ada &amp; Co</n>Ampersand, less than, greater than, and double quote are escaped in text content.
{"my key":1}<my_key>1</my_key>Characters XML does not allow in a name become underscores.
{"2nd":1}<_2nd>1</_2nd>A name cannot start with a digit, so an underscore is prefixed.
[{"id":1}]<root> <item>...</item> </root>A top level array is wrapped, because XML allows only one root element.

Converting a nested record

Note the escaped ampersand, the repeated tags element, and the self closing element for null.

Input
{
  "id": 42,
  "user": { "name": "Ada & Co" },
  "tags": ["admin", "dev"],
  "deleted": null
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <id>42</id>
  <user>
    <name>Ada &amp; Co</name>
  </user>
  <tags>admin</tags>
  <tags>dev</tags>
  <deleted />
</root>

The apostrophe in a value would be left as is, which is valid in element text content. Only ampersand and less than strictly require escaping there, and this converter also escapes greater than and double quote for safety.

Common Pitfalls

Converting back is ambiguous, so the round trip is lossy

A single element cannot be distinguished from a one item array, so a tags element appearing once could have come from either. XML also has no number type, so 42 and "42" produce identical markup. Nothing is lost going to XML, but reconstructing the original JSON from that XML requires knowledge the document does not carry, usually a schema.

{"tags":["a"]}   ->  <tags>a</tags>
{"tags":"a"}     ->  <tags>a</tags>

Everything becomes an element, never an attribute

If the consumer expects an id as an attribute rather than a child element, this output will not satisfy it. There is no convention in JSON for marking a key as an attribute, so the converter cannot infer the intent. Edit the output by hand for a small document, or use a schema driven serializer for anything larger.

No namespaces are emitted

SOAP envelopes and most enterprise schemas require namespace declarations and prefixed element names. The output here has neither, so it is a starting point for a request body rather than a finished one. Add the envelope and the namespace attributes after converting.

How to Use

  1. Paste your JSON: Paste the JSON you need to hand to an XML consumer, such as a SOAP request body.
  2. Click Convert: The tool generates well-formed XML with proper indentation and an XML declaration.
  3. Copy the XML: Copy the XML output for use in SOAP services, legacy systems, or XML-based configurations.

Key Features

  • Includes XML declaration with UTF-8 encoding
  • Proper escaping of special characters (&, <, >, ")
  • Nested objects and arrays are converted to nested XML elements
  • Clean indentation for readable XML output

Use Cases

  • Integrating JSON data with SOAP or XML-based web services
  • Converting JSON configuration to XML format for legacy systems
  • Generating XML documents from JSON data for data exchange

Frequently Asked Questions

Is the generated XML valid?

Yes. The output has an XML declaration, exactly one root element, escaped special characters, and element names that satisfy the XML naming rules, including keys that start with a digit and top level arrays.

How are arrays converted to XML?

Array items repeat the element name of the key that held them, producing sibling elements. A top level array is the exception: it is wrapped in a single root element with each entry written as an item element, because XML permits only one root.

What about JSON keys with special characters?

Characters that XML does not allow in a name are replaced with underscores. A name that would begin with a digit or a hyphen also gets an underscore prefix, so the key 2nd becomes the element _2nd rather than invalid markup.

Is the root element customizable?

Currently, the root element is named 'root' by default. You can rename it in the output after copying.

Does the converter support XML attributes?

JSON keys are converted to XML elements, not attributes. If you need attributes, you can manually edit the XML output after conversion.

Can I convert the XML back to JSON?

Not reliably, and not with this tool. A single element and a one item array produce identical markup, and XML has no number type, so 42 and "42" are indistinguishable. Reconstructing the original JSON needs a schema that says which elements repeat and which are numeric.

Why is there no SOAP envelope or namespace?

Envelopes and namespaces are specific to the service you are calling, and nothing in your JSON indicates which ones to use. The converter produces a clean document body. Wrap it in the envelope and add the namespace declarations your endpoint requires.