🔄 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.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<order>
<id>4417</id>
<customer>Ben & Jerry's</customer>
<notes>Deliver <before> 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
- Paste your JSON data into the input text area
- Set custom root tag name if needed
- 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 &, < becomes <, > becomes > 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}
- The ampersand is escaped to &
- The array becomes repeated <item> elements inside <items>
- 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
| Character | Entity | Required in |
|---|---|---|
| & | & | Text and attributes — always, it starts an entity reference |
| < | < | Text and attributes — always, it starts a tag |
| > | > | Text, by convention; strictly required only after "]]" |
| " | " | Attribute values quoted with double quotes |
| ' | ' | Attribute values quoted with single quotes |
Element name rules
| Name | Valid? | Why |
|---|---|---|
| order | Yes | Letters only |
| order_id | Yes | Underscores are allowed |
| order.id | Yes | Full stops are allowed |
| order id | No | No spaces — becomes order_id |
| 1st | No | Cannot start with a digit — becomes _1st |
| xml-version | No | Names 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?
Can I customize the root XML tag?
How are JSON arrays represented in XML?
What happens to JSON keys that are not valid XML names?
Should values become attributes or elements?
What about null?
Why convert to XML at all these days?
Is my data uploaded?
References & Further Reading
- W3C — XML 1.0 specification — The rules for well-formedness, element names and character escaping applied here
- MDN — JSON — The JSON data types being mapped from