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.

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.

⚠️ 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.