What does this tool do?
This free XML to JSON converter turns an XML document into clean JSON as you type, and converts JSON back to XML with the reverse toggle. It runs entirely in your browser — nothing you paste is uploaded — so it is safe for config files and API payloads, and it works offline once loaded. If your source is YAML rather than XML, the home page converts YAML to JSON the same in-browser way.
How XML maps to JSON
XML and JSON do not have a one-to-one structure, so this tool uses the widely-adopted convention:
- Attributes become keys prefixed with
@. So<user id="7">becomes{ "user": { "@id": "7" } }. - Element text becomes the value directly when an element has no attributes or children; otherwise it is stored under a
#textkey. - Repeated sibling tags with the same name are collected into a JSON array automatically.
- Nested elements become nested objects, mirroring the document tree.
The reverse direction (JSON to XML) reads the same convention back: @ keys become attributes, #text becomes element text, and arrays become repeated tags.
Real-world examples
The most common reason to convert XML to JSON is to pull a legacy payload — a SOAP response, an RSS feed, or an old config file — into a modern app that expects JSON. For example, this RSS item:
<item> <title>Release 2.0</title> <link>https://example.com/2.0</link> <category domain="release">major</category> </item>
becomes JSON your JavaScript can read directly:
{
"item": {
"title": "Release 2.0",
"link": "https://example.com/2.0",
"category": { "@domain": "release", "#text": "major" }
}
}
Both conventions are visible here: the domain attribute became @domain, and because <category> has an attribute and text, the text moved into #text. The same pattern handles SOAP envelopes, Atom feeds, sitemaps, and office-format XML.
Convert XML to JSON in code (Python, JavaScript, CLI)
This page is the zero-install option; inside a script the libraries are short:
- Python:
import xmltodict, json; print(json.dumps(xmltodict.parse(open("in.xml").read())))—xmltodictuses the same@attr/#textconvention as this tool. - JavaScript:
new DOMParser().parseFromString(xml, "application/xml")in the browser and walk the tree, orfast-xml-parserin Node. - Command line:
yq -p=xml -o=json '.' in.xmlconverts an XML file to JSON in one command.
How to use it
- Paste XML on the left; the JSON appears live on the right.
- Pick 2 spaces, 4 spaces, or tabs with the Indent control.
- Copy the result or Download a
.jsonfile. - Malformed XML shows a clear parse error so you can fix it fast.
XML vs JSON
XML is verbose and document-oriented, with attributes, namespaces and a rich schema ecosystem — still common in enterprise systems, SOAP APIs, RSS/Atom feeds, and office file formats. JSON is lighter and maps directly onto the data structures of modern programming languages, which is why most web APIs moved to it. Converting XML to JSON is a frequent step when modernizing an integration or pulling a legacy feed into a JavaScript app.
Common uses
- Convert a SOAP or legacy API's XML response into JSON for a modern front end.
- Turn an RSS/Atom feed into JSON for processing.
- Inspect a dense XML config by viewing it as structured JSON.
FAQ
How are XML attributes represented in JSON?
Each attribute becomes a key prefixed with @. For example <user id="7"> becomes { "user": { "@id": "7" } }.
What happens to repeated tags?
Repeated sibling elements with the same name are collected into a JSON array automatically.
Does it handle XML namespaces?
Yes. A namespaced tag like <ns:item> keeps the prefix in the JSON key ("ns:item"), so nothing is lost.
What about CDATA sections?
The text inside a <![CDATA[ … ]]> block is treated as the element's text content, exactly like ordinary text.
Does it work offline?
Yes. Once the page has loaded it runs without a network connection — the XML parser is your browser's own.
Can I convert JSON back to XML?
Yes. Switch the toggle to JSON → XML; @ keys become attributes, #text becomes element text, and arrays become repeated tags.
Is my data uploaded?
No. Conversion runs entirely in your browser; nothing you paste leaves your device.
Why do I get a parse error?
XML must be well-formed: every tag closed, one root element, and attribute values quoted. The error message points to the problem.