XML ↔ JSON Transformer

Convert XML to JSON and back, live, in both directions. Attributes, nesting and repeated tags all handled correctly.

100% client-side

XML

0 characters

JSON

0 characters

What is XML ↔ JSON Transformer?

XML and JSON are two different text formats for structuring data — XML wraps values in named tags like <title>Dune</title>, while JSON uses key-value pairs like { "title": "Dune" }. Older systems (SOAP APIs, config files, RSS feeds) often speak XML, while most modern APIs speak JSON, so converting between them is a common task. This tool does it live, in both directions, without losing attributes or repeated elements.

How to use XML ↔ JSON Transformer

  1. Paste your XML into the XML panel on the left (or click Example to load a sample) — the JSON panel updates automatically.
  2. You can also edit the JSON panel directly and the XML side will update to match.
  3. Use Copy or Download on either panel to grab that side's result.
  4. Use Clear to start over.

How XML ↔ JSON conversion works

XML elements, attributes and text don't map onto JSON in one obvious way, so this tool follows one explicit, consistent convention in both directions:

  • An XML attribute becomes a JSON key prefixed with @.
  • Text content that coexists with attributes or child elements becomes a #text key; an element with only text (no attributes, no children) collapses to a plain JSON string.
  • A single child element stays a plain object; as soon as a second sibling with the same tag name appears, both are collected into a JSON array — so repeated tags never silently overwrite each other.
// XML
<library>
  <book id="1"><title>Dune</title></book>
  <book id="2"><title>Foundation</title></book>
</library>

// JSON
{
  "library": {
    "book": [
      { "@id": "1", "title": "Dune" },
      { "@id": "2", "title": "Foundation" }
    ]
  }
}

Conversion uses the browser's native DOMParser and XMLSerializer-equivalent string building — no external library, no server calls.

Frequently asked questions

How are XML attributes represented in the JSON output?

Each attribute becomes a JSON key prefixed with @, e.g. the id attribute on <book id="1"> becomes "@id": "1". Text content that coexists with attributes or child elements becomes a #text key.

What happens to repeated sibling elements, like several <book> tags?

They become a JSON array. A single <book> stays a plain object, but as soon as a second sibling with the same tag name appears, both are collected into an array so no data is silently overwritten.

Does it support CDATA sections?

Yes on import — CDATA content is read as plain text. Converting back to XML always emits escaped text rather than re-wrapping it in a CDATA block, since a JSON string can't record that it was originally CDATA.

Is it safe to paste sensitive XML or JSON here?

Yes. All parsing and conversion happens in your browser using the native DOMParser and JSON APIs; nothing is ever sent to a server.