Home/ Glossary/ XML ↔ JSON
Konverter

XML ↔ JSON

The XML to JSON Converter transforms XML documents into JSON and converts JSON back to XML. It is the companion tool to json-xml and provides the same bidirectional conversion with a focus on XML-first workflows. Use it when you receive XML from a SOAP service, RSS feed, or legacy system and need to process it with modern JSON tooling.

When would I convert XML to JSON?

XML was the dominant data exchange format before JSON rose to prominence in the 2000s. Many legacy enterprise systems, SOAP web services, RSS/Atom feeds, and XML-based APIs still output XML. Modern applications, microservices, and front-end code overwhelmingly prefer JSON for its simplicity and native JavaScript compatibility. Converting XML to JSON allows developers to process XML-sourced data with JSON libraries, query it with jq, validate it with JSON Schema, or store it in document databases like MongoDB.

How does the converter work?

For XML-to-JSON, the tool parses the XML using a DOM parser into an element tree. Each XML element becomes a JSON key with its child elements as the value. Text content is mapped to a string value. Multiple sibling elements with the same tag name are collected into a JSON array. XML attributes are mapped to JSON keys prefixed with @ (e.g. <user id='1'> → {"@id":"1"}). For JSON-to-XML, keys starting with @ are emitted as attributes, arrays of objects become repeated sibling elements, and a configurable root element wraps the output.

Typical Use Cases

  • Parsing a SOAP XML response into JSON for processing in a REST-oriented application
  • Converting an RSS or Atom feed to JSON for easier consumption in JavaScript
  • Transforming legacy XML exports to JSON for import into a modern database
  • Using jq to query configuration or data stored in XML by first converting to JSON

Step-by-step Guide

  1. Step 1: Paste your XML or JSON content into the input field.
  2. Step 2: Select the conversion direction: XML → JSON or JSON → XML.
  3. Step 3: Optionally configure attribute prefix and root element name.
  4. Step 4: Copy or download the converted output.

Example

Input
<users><user id="1"><name>Alice</name></user></users>
Output
{"users":{"user":{"@id":"1","name":"Alice"}}}

Tips & Notes

  • XML requires a single root element; when converting JSON to XML the tool wraps the output in <root> by default – change this to match your target schema.
  • If your XML has namespace prefixes (ns:element), they are preserved as part of the key name in JSON.
  • Use the json-xml tool if your workflow is JSON-first; xml-json is optimized for XML-first input.

Frequently Asked Questions

What is the difference between xml-json and json-xml?
Both tools offer bidirectional conversion, but xml-json is optimized for starting from XML (the input is XML by default), while json-xml is optimized for starting from JSON. Functionally they are equivalent.
How are XML namespaces handled?
Namespace prefixes are preserved in element key names (e.g. soap:Envelope → {"soap:Envelope":...}). Full namespace URI resolution is not performed since JSON has no namespace concept.
Can I convert large XML files?
The tool processes the file in the browser. Files up to a few megabytes work well. For very large XML files (tens of MB), a command-line tool like xq (XML + jq) is more efficient.
XML ↔ JSON
Convert XML to JSON and JSON to XML — live, bidirectional, and with syntax validation.
Open Tool