Convert XML to JSON
online, free & instant
Paste your XML and get clean, structured JSON output in one click. Attributes, nested elements, and namespaces are all preserved. No signup, no server — runs entirely in your browser.
Open XML to JSON ConverterXML to structured JSON in three steps
No account. No upload. No nonsense.
Fully Private
Your XML data never leaves your device. All parsing happens in JavaScript, right in your browser.
Preserves Structure
Attributes, namespaces, nested elements, and mixed content are all mapped to a clean JSON representation.
Instant Results
No server round-trips. The converter responds immediately, even for large XML documents.
Related JSON tools
Common questions answered
Is the XML to JSON converter free?
Yes, completely free with no account or signup required. Use it unlimited times.
How are XML attributes handled in the JSON output?
XML attributes are converted to JSON properties prefixed with '@' (e.g., @id, @class). This convention preserves the attribute data while keeping it distinguishable from child elements.
Does the converter support XML namespaces?
Yes. Namespace prefixes are preserved in the JSON key names (e.g., 'soap:Envelope'), so you retain the full structure of your XML document.
Is my XML data sent to a server?
No. All parsing and conversion happens entirely in your browser using JavaScript. Your data never leaves your device.
How are nested XML elements converted to JSON?
Nested child elements become nested JSON objects. Repeated sibling elements with the same tag name are automatically grouped into JSON arrays, preserving the hierarchical structure.
Converting XML to JSON
XML to JSON conversion transforms hierarchical markup into compact JSON. This is common when integrating with SOAP APIs, processing RSS/Atom feeds, reading Android resources, or migrating from XML-based systems to modern JSON APIs. The conversion reduces verbosity significantly.
XML attributes become JSON properties (prefixed with @), text content maps to #text, repeated elements become arrays, and namespaces are preserved or stripped. This tool handles all these edge cases, producing clean JSON from any well-formed XML. Mixed content (elements with text and children) uses a consistent mapping strategy.
<?xml version="1.0"?>
<user role="admin">
<name>Alice</name>
<age>30</age>
<tags>
<tag>dev</tag>
<tag>lead</tag>
</tags>
</user>
{
"user": {
"@role": "admin",
"name": "Alice",
"age": "30",
"tags": {
"tag": ["dev", "lead"]
}
}
}
Get the most out of this tool
- XML attributes convert to @ prefixed properties: <user role="admin"> becomes {"@role": "admin"}.
- Repeated elements with the same name automatically become JSON arrays — no configuration needed.
- XML namespaces add complexity — strip them before converting if you don't need namespace-qualified keys.
How XML-to-JSON conversion works
XML and JSON represent fundamentally different data models, making their conversion a non-trivial mapping problem. XML is a document format with a tree of nodes — elements, attributes, text content, CDATA sections, comments, and processing instructions. JSON is a data format with a tree of values — objects, arrays, strings, numbers, booleans, and null. Converting XML to JSON requires making decisions about how each XML concept maps to these JSON primitives.
Element text content is typically placed in a special key like #text or _text when an element also has attributes or child elements. For example, <name lang="en">Alice</name> might become {"name": {"lang": "en", "#text": "Alice"}}. This convention preserves both the attribute and the text content without losing information, though it produces more verbose JSON than a simple {"name": "Alice"} would.
XML attributes present a mapping challenge because JSON objects have no concept of attributes — only keys and values. The most common approach prefixes attribute names with @ to distinguish them from child elements: {"element": {"@id": "123", "child": "value"}}. Alternative approaches merge attributes directly into the object or place all attributes in a dedicated $ or _attr key. The chosen convention must be consistent and documented when sharing converted JSON with other systems.
Repeated XML sibling elements of the same name should become a JSON array. The challenge is that an element appearing once and an element appearing multiple times look structurally identical when viewed in isolation. A robust converter scans all children of a node before deciding whether to use an array — if a tag name appears more than once among siblings, it becomes an array; if it appears only once, it may be either a single value or a single-element array depending on the converter's configuration.
XML namespaces add another layer of complexity. A namespaced element like <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> must be handled either by stripping the namespace prefix, including it in the key name ("soap:Body"), or expanding it with the full URI. Most practical XML-to-JSON converters strip namespace prefixes or include them verbatim, with full namespace URI expansion reserved for semantic web applications.
SOAP and WSDL web services — common in enterprise Java, .NET, and SAP systems — produce heavily nested XML with namespaces, envelope structures, and type annotations. Converting SOAP responses to JSON is often the first step in building a REST adapter over a legacy SOAP service. The converted JSON can then be cleaned up with transformation steps to remove envelope boilerplate and expose only the business data.
RSS and Atom feeds are XML formats used for blog syndication and news aggregation. Converting them to JSON enables consumption by JavaScript applications that natively handle JSON but would require an XML parsing library to handle the original feed format. JSON-formatted feed data can be stored in document databases, filtered with JSONPath, and served via REST APIs to feed reader applications.
When developers convert XML to JSON
XML-to-JSON conversion pitfalls
- Losing XML attribute information: A converter that ignores XML attributes and only processes element content silently drops critical data — like the
idattribute of a record or thetypeattribute of a field. Always verify that attributes are represented in the JSON output, typically as@keyprefixed properties. - Single-element arrays appearing as objects: When an XML element appears only once as a child, some converters produce a JSON object instead of a single-element array. This causes type errors in downstream code that expects an array. Configure your converter to always produce arrays for elements that can repeat, or normalize the output to handle both cases.
- Stripping namespace context needed for semantics: XML namespaces distinguish elements with the same local name but different vocabularies — for example,
dc:title(Dublin Core) vsatom:title. If your converter strips all namespace prefixes, these distinctions are lost. Preserve namespace information in the JSON when semantics depend on it. - Mixed content (text + child elements) garbled: XML supports mixed content — elements containing both text nodes and child elements interleaved. Most JSON converters handle this poorly, either dropping the text nodes or merging them incorrectly. Inspect mixed-content elements carefully after conversion to verify all text is preserved.
- Assuming XML structure is consistent: Unlike JSON Schema, XML DTDs and XSDs are often not enforced at runtime. Real-world XML files from the same source can vary significantly in structure. Always validate the converted JSON against your expected structure rather than assuming the XML was consistent.
Additional frequently asked questions
How are XML attributes handled in the JSON output?
XML attributes are typically represented as object properties prefixed with @ to distinguish them from child elements. For example, <item id="1"> becomes {"item": {"@id": "1"}}. Some converters use a dedicated _attributes key instead. The exact convention varies by converter — check your tool's documentation to understand the mapping used.
What happens to XML comments and processing instructions?
XML comments (<!-- ... -->) and processing instructions (<?xml-stylesheet ... ?>) have no JSON equivalents and are discarded during conversion. If comments contain important information like field descriptions or version markers, extract that information into dedicated JSON properties before converting.
Can I convert XML with CDATA sections to JSON?
CDATA sections (<![CDATA[...]]>) wrap raw text content that contains characters which would otherwise need XML escaping, like < and &. During XML-to-JSON conversion, CDATA content is treated as plain text — the CDATA wrapper is removed and the raw text becomes a JSON string value, with no escaping artifacts.
Is there a way to convert only part of an XML document to JSON?
XPath expressions can extract specific nodes from an XML document before conversion. For example, if you only need the <items> section of a large SOAP envelope, extract that subtree with XPath first and then convert it to JSON. Command-line tools like xmllint support XPath extraction that can be piped into an XML-to-JSON converter.