JSON to XML
Paste or upload JSON to convert it into XML. Runs in your browser.
Pasted text and chosen files stay on this device. Nothing is sent to a server.
Drop a file here, choose one, or paste.
How to use it
- 1
Paste the JSON and set the conventions.
- 2
Read the convention line; it is what a consuming system has to agree with.
What it does
JSON and XML are both trees and they disagree about almost everything else. There are no arrays in XML, no null, and no single required root — so a conversion is a set of conventions, and they should be visible.
Emit elements for object members, repeat the element for each array item, and write a declared root. Report the convention used for arrays, nulls and the root.
Why it works this way
An array becomes either repeated sibling elements or a wrapper element with the items inside. Both are common and they are not interchangeable — a reader expecting one gets nothing from the other.
JSON null has no XML form. An empty element, an explicit nil attribute and an omitted element are three different statements, and choosing silently means the reader cannot tell which was meant.
XML requires a single root. A JSON array at the top level has none, so one is supplied by name and the name is reported because it is a choice, not a fact.
Examples
{"a": [1, 2]}<a>1</a><a>2</a>
{"a": null}<a/>
Inputs and outputs
- JSON text
- array convention: repeated element / wrapped in a container
- null: empty element / xsi:nil / omit
- root element name
- XML text
- the convention applied, named
Edge cases
- arrays of arrays
- keys that are not valid XML names
- text containing < and &
- an array at the top level — needs a supplied root
- mixed arrays of objects and scalars
Frequently asked questions
Why is my array not an <array> element?
Because the convention is repeated elements by default. The wrapped form is available and the choice is reported either way.
What happened to null?
It became whichever of the three conventions you chose, and the report names it so the consumer can rely on it.
Related tools
Sources
- W3C XML 1.0, section 2 (Documents must have exactly one root element)