XML to JSON

Convert XML documents to JSON.

Open tool

Overview

The XML-to-JSON converter rewrites an XML document into a JSON representation. Element names become object keys, attributes are folded into the same object with a configurable prefix, and child elements with the same name collapse into arrays.

It's the right tool for moving an XML payload — a SOAP envelope, a legacy config, an RSS feed — into a JSON-consuming pipeline. Backend developers and integration engineers reach for an xml to json converter to bridge a SOAP service into a REST microservice, or to feed XML logs into a JSON-based analytics tool.

How it works

XML's data model has elements, attributes, text content, and mixed content; JSON has only objects, arrays, and scalars. The converter picks a convention to map one to the other: each element becomes an object; attributes are stored under a prefix (default @, so <user id="1"> becomes {"@id":"1"}); text content goes under a key (default #text); and repeated child elements collapse into an array.

Single child elements stay as values ({"name":"Alice"}), not arrays of one. The "force array" option lets you mark specific element names that should always be arrays so single-element lists don't collapse to scalars — useful when round-tripping schemas where cardinality matters.

Examples

<order id="1">
  <item sku="abc">Widget</item>
  <item sku="def">Gizmo</item>
</order>
{
  "order": {
    "@id": "1",
    "item": [
      { "@sku": "abc", "#text": "Widget" },
      { "@sku": "def", "#text": "Gizmo" }
    ]
  }
}
<user>
  <name>Alice</name>
</user>
{ "user": { "name": "Alice" } }

FAQ

How are repeated elements handled when there's only one?

By default, a single child element becomes a scalar or object, not an array of one. Mark the element name in the "force array" list if you need stable cardinality across documents with varying counts.

What about XML namespaces?

Namespace prefixes are preserved in the JSON keys (ns:user becomes "ns:user"). The namespace declaration itself can be moved to a top-level @xmlns key or dropped — pick the convention your consumer expects.

Is the round trip lossless?

For pure element trees with attributes, yes. Mixed content (text interleaved with elements) loses some structure because JSON has no peer for it. The converter falls back to a synthetic representation for mixed content.

Try XML to JSON

An unhandled error has occurred. Reload ×