Tools
Guides

JSON ↔ XML Converter

JSON

Convert between JSON and XML. Nested objects are wrapped under a configurable root element.

100% client-side No backend
Input
Output
On this page

What is a JSON ↔ XML converter?#

JSON and XML are two different ways to write down structured data, and they are not interchangeable at the syntax level — one uses braces and brackets, the other uses angle-bracket tags. A converter between them does not “compress” or “encode”; it re-expresses the same tree of values in the other notation, so a system that only speaks XML can consume data that arrived as JSON, and vice versa.

The mapping is mostly mechanical but has two well-known rough edges. First, XML requires exactly one root element wrapping everything, whereas JSON happily lets the top level be a bare object or array — so going JSON to XML always means choosing a name for that outer wrapper. Second, XML elements can carry attributes (<a id="7">), which JSON has no native equivalent for; the common convention is to park them under @-prefixed keys, and any text living alongside attributes under a #text key.

This page converts in both directions in the browser: JSON to XML (wrapping your value under a root element you name), and XML to JSON (unpacking attributes into @-keys and, by default, stripping the outer root so you get the inner value back).

How to use it#

  1. Pick the direction with the JSON → XML / XML → JSON toggle at the top-left of the toolbar.
  2. Type or paste into the Input pane on the left.
    • JSON → XML expects valid JSON. Any top-level value is wrapped under the root element.
    • XML → JSON expects a well-formed XML document. The single outer element is unwrapped automatically, so you get its inner content as JSON.
  3. In JSON → XML mode, set the Root element field (default root) to name the wrapper tag — for example user, feed, response. XML mandates a single root, so this name is always required.
  4. The result appears live in the Output pane. Click Copy to grab it.
  5. Sample loads a small document suited to the current direction; Clear resets both panes.

Key features#

  • Both directions, one tool. A single toggle flips between JSON-to-XML and XML-to-JSON, with the input pane retargeted automatically.
  • Configurable root element. Because XML cannot exist without a single outer element, you name the wrapper; the converter handles the wrapping for any JSON top-level shape.
  • Proper XML declaration. JSON-to-XML output begins with the standard <?xml version="1.0" encoding="UTF-8"?> prolog and is pretty-printed with two-space indentation.
  • Attributes round-trip. XML-to-JSON preserves element attributes under @-prefixed keys, and text that sits next to attributes is kept under #text, so nothing is silently dropped.
  • Number-aware parsing. XML is all text; the parser coerces numeric-looking element values back to JSON numbers (so <age>36</age> becomes 36, not "36").

Worked example#

JSON → XML#

With the direction set to JSON → XML and the root named root, load Sample:

{
  "name": "Ada",
  "age": 36,
  "skills": ["math", "logic"]
}

The converter wraps everything under <root> and expands the array the way XML needs — each entry becomes its own element with the same tag:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <name>Ada</name>
  <age>36</age>
  <skills>math</skills>
  <skills>logic</skills>
</root>

Change the Root element field to person and the wrapper becomes <person> / </person> instead — the inner structure is untouched.

XML → JSON#

Flip to XML → JSON and load Sample:

<?xml version="1.0"?>
<root><name>Ada</name><age>36</age></root>

The outer <root> is stripped, and the inner elements become JSON properties, with 36 recognised as a number:

{
  "name": "Ada",
  "age": 36
}

Attributes are preserved too. An element like <a id="7">label</a> produces { "@id": "7", "#text": "label" } — the attribute lives under @id, the text under #text, and neither is lost.

FAQ#

Why does my JSON array turn into repeated XML elements instead of one wrapper with items inside?#

That is how XML represents a list: there is no “array” construct, so each entry has to be its own element with the same tag name. A JSON array ["math", "logic"] under the key skills therefore becomes two sibling <skills> elements, not a single <skills> containing children. This is the standard, schema-friendly mapping — XML consumers expect it.

In XML → JSON, where did my outer element go?#

The converter unwraps the single root automatically. XML forces exactly one top-level element, but in JSON that wrapper is usually redundant — <root><name>Ada</name></root> carries no information in root that JSON needs. Stripping it gives you the meaningful inner value directly. If you genuinely need the root preserved, keep it as a normal element and access it by name.

Why is 36 a number in the output, not a string?#

XML has no separate number type — everything between the tags is text. The parser applies numeric coercion, so an element whose text looks like a number (36, 3.14) comes back as a JSON number. That is convenient for typical data, but it also means a value like a product code <code>007</code> will lose its leading zeros — store such values as attributes or accept them as strings.

Can it convert any XML document?#

Well-formed XML yes, including namespaces in tags, attributes, self-closing elements, and declarations. It does not resolve DTDs, validate against a schema, or fetch external entities — processing is local and text-only, which also means it is safe to paste documents you do not fully trust.