OnlyFormat

XML to JSON Converter

Convert XML data to JSON format instantly. Paste text or upload a .xml file.

No data sent to server
XML Input
JSON Output

Related Tools

What is XML to JSON?

XML still powers many enterprise systems — SOAP APIs, RSS/Atom feeds, financial protocols, government data, configuration files. JSON is the modern API standard. Converting XML → JSON lets you work with legacy data in modern JavaScript apps, store XML in JSON-only databases (MongoDB, DynamoDB), or feed XML data into JSON-only tools (most analytics platforms).

Common scenarios: RSS feed parsing in JavaScript, SOAP API integration from a JSON-based backend, migrating XML configs to JSON for newer tools, XML log analysis, government open data (often XML), EDI / banking formats.

Conversion example

# XML
<?xml version="1.0"?>
<users>
  <user id="1">
    <name>Alice</name>
    <age>30</age>
  </user>
  <user id="2">
    <name>Bob</name>
  </user>
</users>

# JSON
{
  "users": {
    "user": [
      { "@id": "1", "name": "Alice", "age": "30" },
      { "@id": "2", "name": "Bob" }
    ]
  }
}

XML → JSON challenges

XML and JSON have fundamentally different data models. The conversion is “lossy” in subtle ways:

  • Attributes vs elements: XML has both; JSON only has key-value. Convention: attributes prefixed with @ (e.g., “@id”)
  • Single child vs array: <item>a</item> alone vs <item>a</item><item>b</item> produce different shapes — auto-detect or schema-aware mapping needed
  • Mixed content: <p>Hello <b>world</b>!</p> (text + nested elements) is hard to represent in JSON
  • XML namespaces: xmlns:ns=... prefixes are typically stripped or kept as keys with :
  • Comments and processing instructions: usually stripped
  • Numeric vs string types: XML stores everything as text; conversion may produce strings even for numbers

How to Use

  1. Paste XML data, or upload a .xml file.
  2. Click Convert.
  3. Review JSON output — verify attribute handling and array shapes.
  4. Copy or download as .json.

Privacy: Conversion runs in your browser. No upload.

Two Ways of Describing the Same Thing

XML and JSON both represent hierarchical data, but they were designed with different priorities. XML came from the document world, so it distinguishes between elements, attributes, and text content, and it supports namespaces, comments, and schemas. JSON came from JavaScript, so it has exactly six types and no ceremony.

That mismatch is what makes the conversion interesting. XML has concepts JSON simply does not, so something has to give.

Where the Two Models Do Not Line Up

Attributes versus child elements. XML can write the same information either as <user id="7"/> or <user><id>7</id></user>. JSON has only properties, so attributes have to be folded in somehow, usually with a naming convention.

Repeated elements. Two <item> elements become an array; one <item> becomes a single value. That means the shape of your JSON changes depending on how many records the XML happened to contain, which quietly breaks code that assumed an array.

Everything is text. XML has no native number or boolean type without a schema, so <count>5</count> is the string “5” unless something decides otherwise.

Mixed content. An element containing both text and child elements — common in documents — has no natural JSON equivalent at all.

Namespaces and comments. Neither exists in JSON. Prefixes usually survive as part of names; comments are dropped.

FAQ

How are XML attributes handled?

Attributes prefixed with @. <user id=“1”> becomes {"@id": "1"}. This is the Badgerfish convention used by most modern XML→JSON converters.

What about repeated elements?

Repeated sibling elements are automatically grouped into a JSON array. Single-occurrence elements stay as objects. This auto-detection isn’t perfect — check the output if your XML schema expects arrays even when only one element appears.

How is text content represented?

If an element has both attributes and text, text is placed under #text key: <p style=“bold”>Hello</p>{"@style": "bold", "#text": "Hello"}. If only text, the element value is just the string.

Can I parse SOAP envelopes?

Yes — paste the entire SOAP envelope. The deep nesting (soap:Envelope/soap:Body) becomes nested JSON. For SOAP-specific tooling, use libraries like strong-soap (Node.js) or zeep (Python).

My XML has CDATA sections — how are they handled?

CDATA content is extracted as text. <![CDATA[...]]> wrappers are removed; the inner content becomes a regular JSON string. Special characters like < inside CDATA are preserved.

Why is my conversion slow / browser hanging?

Very large XML (50+ MB, deeply nested) can stress the browser. For large files, use command-line tools like xq (XML version of jq) or xmlstarlet.

Why did a single record come out as a value instead of an array?

Because XML gives no way to distinguish “a list that happens to have one item” from “a single item”. Code consuming the result should handle both shapes, or the source should use a schema that makes the intent explicit.

What happens to XML attributes?

They are folded into the object alongside child elements, typically with a marker in the property name to distinguish them, since JSON has no separate concept of attributes.

Are numbers converted from text?

XML without a schema has no types, so values arrive as text. Treat type conversion as something to handle deliberately rather than assume.

Is this safe with untrusted XML?

Parsing happens with the browser’s built-in XML parser, which does not resolve external entities, so the classic XXE attack does not apply. Nothing is uploaded either.

⚠️ Reference Only

Output is generated based on your input and is provided for reference. Results may vary depending on your specific use case, edge cases, or environment-specific behavior. We do not guarantee accuracy of conversions, validations, or computed values.

Always verify critical outputs against official documentation or production environments. We are not responsible for any decisions or losses based on these tool results.