🔄 JSON to XML & XML to JSON Converter

A JSON to XML converter that runs both directions and re-parses its own output before showing it, so what you copy is known to be well-formed.

Free No Signup Required Browser-Based
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <order>
    <id>4417</id>
    <customer>Ben &amp; Jerry's</customer>
    <notes>Deliver &lt;before&gt; 5pm</notes>
    <items>
      <item>
        <sku>A-100</sku>
        <qty>2</qty>
      </item>
      <item>
        <sku>B-220</sku>
        <qty>1</qty>
      </item>
    </items>
    <paid>true</paid>
    <discount/>
  </order>
</root>

Converted in this tab — nothing is uploaded. Values are escaped, keys are corrected to legal XML names, and the output is checked with the browser’s own XML parser before it is shown.

What JSON to XML & XML to JSON Converter Does

JSON and XML both describe structured data, and neither maps cleanly onto the other. JSON has six types — object, array, string, number, boolean and null — while XML has elements, attributes and text, with no built-in notion of what any of it means. Converting between them always involves choices, and a converter that hides those choices is making them for you.

Three of them come up every time. Arrays have no name in JSON, so every writer has to invent an element name for the items — a fixed item, or the singular of the parent key, which reads better. Null is an absence, not the four letters "null", so it becomes an empty element. And XML needs exactly one root, so a top-level array or a bare value has to be wrapped.

The part that is not a choice is escaping. Ampersands, less-than and greater-than must be replaced with entities, or the document is not well-formed and no parser will read it — a company name like "Ben & Jerry’s" is enough to break output that skips this. Element names have rules too: they cannot contain spaces and cannot begin with a digit, so a key like "1st" needs correcting rather than passing through.

This converter handles all of that, and then checks its own output with the browser’s XML parser before showing it to you, so what you copy is known to parse. It runs in the other direction too: XML in, JSON out, parsed with the same browser parser so malformed input is reported rather than guessed at.

Going backwards has its own choices. Attributes have no JSON equivalent, so they become keys prefixed with an @ — the convention most widely used, though Badgerfish and Parker each do it differently. And repeated sibling elements become an array while a single one does not, which means the shape of the JSON depends on how many children happened to be in that particular document. That is the clearest illustration of why the two formats do not round-trip.

How to Use JSON to XML & XML to JSON Converter

  1. Paste your JSON data into the input text area
  2. Set custom root tag name if needed
  3. Click Copy XML to use in SOAP APIs, legacy services, or XML configuration files

Formula Used by JSON to XML & XML to JSON Converter

The mapping, type by type

object → nested elements array → repeated child elements string/number/boolean → text content null → empty element

escaping
& becomes &amp;, < becomes &lt;, > becomes &gt; in all text content
element names
letters, digits, hyphen, underscore and full stop; may not start with a digit or hyphen

Worked example

{"customer": "Ben & Jerry’s", "items": [{"sku": "A-100"}], "discount": null}

  1. The ampersand is escaped to &amp;
  2. The array becomes repeated <item> elements inside <items>
  3. null becomes an empty <discount/>

Result: Well-formed XML that a parser will accept — which the unescaped version would not be.

Characters that must be escaped

CharacterEntityRequired in
&&amp;Text and attributes — always, it starts an entity reference
<&lt;Text and attributes — always, it starts a tag
>&gt;Text, by convention; strictly required only after "]]"
"&quot;Attribute values quoted with double quotes
'&apos;Attribute values quoted with single quotes

Element name rules

NameValid?Why
orderYesLetters only
order_idYesUnderscores are allowed
order.idYesFull stops are allowed
order idNoNo spaces — becomes order_id
1stNoCannot start with a digit — becomes _1st
xml-versionNoNames beginning "xml" in any case are reserved

How to Read Your Result

Pick the array naming that matches the consumer

If the XML is going into a system with a schema, the element names are already decided and you should match them. If it is for a person to read, the singular form is clearer. Neither is more correct in the abstract.

The conversion is not lossless

Round-tripping XML through JSON and back loses attributes, comments, processing instructions, namespaces and node order guarantees. Going the other way, XML has no native way to say that a value is a number rather than a string. Do not treat either direction as reversible.

Everything becomes text

XML text content is untyped, so 42 and "42" are indistinguishable in the output. If the consumer needs types, it needs a schema — XSD or similar — which describes types separately from the document.

Limitations & Accuracy Notes

  • JSON to XML: values become element text; nothing is emitted as an XML attribute. That is a choice, and the other convention is equally common.
  • XML to JSON: every value comes back as a string, because XML text is untyped — 42 becomes "42".
  • XML to JSON: an element that appears once becomes an object and the same element appearing twice becomes an array, so the output shape varies with the document rather than with any schema.
  • XML to JSON: comments, processing instructions and mixed content are discarded.
  • No namespace support in either direction.
  • JSON numbers are written as they appear. Very large integers can lose precision when JSON.parse reads them, before this tool ever sees them.
  • Keys are corrected to legal XML names, which means two different keys could in principle produce the same element name.
  • No schema is generated; the output is a document, not a contract.
  • Everything runs in your browser, so very large files are limited by available memory.

Frequently Asked Questions

How does JSON to XML conversion work?
It recursively parses JavaScript Object Notation keys and values into valid XML tags and nested element hierarchies.
Can I customize the root XML tag?
Yes, you can change the default `<root>` element to `<response>`, `<data>`, `<user>`, or any custom tag.
How are JSON arrays represented in XML?
XML has no array type, so an array becomes repeated sibling elements with the same name. That means the distinction between a one-element array and a single value is lost, which is the main reason JSON to XML round trips are not reliably lossless.
What happens to JSON keys that are not valid XML names?
XML element names cannot start with a digit or contain spaces and several punctuation characters, so those keys have to be escaped or rewritten. JSON permits any string as a key, which is why some documents cannot convert cleanly.
Should values become attributes or elements?
There is no canonical answer, which is precisely the problem — different converters choose differently and produce incompatible output from identical input. Elements are the safer default because they nest and repeat; attributes cannot.
What about null?
XML has no null. It is usually rendered as an empty element or an xsi:nil attribute, neither of which a plain parser distinguishes from an empty string. Round-tripping null through XML loses information.
Why convert to XML at all these days?
Legacy integration, mostly — SOAP services, older enterprise systems, and formats like RSS and SVG that are XML by specification. For new work JSON is almost always the better choice.
Is my data uploaded?
No. The conversion runs in your browser.

References & Further Reading

By OnlineToolHubs Team • September 2026