XML to JSON Converter.
Convert XML to clean JSON in one click — with attribute handling, repeated-tags-to-arrays, and namespace support. 100% private: your data never leaves the browser.
No signup · No uploads · No file-size cap
JSON output
Convert XML to JSON online — free and private
An XML to JSON converter turns XML markup into structured JSON that modern APIs and JavaScript can use directly. Paste your XML above, press Convert to JSON, and the parser maps elements, attributes, and text into clean JSON. Unlike server-based tools, this one parses everything in your browser, so you can convert XML to JSON online without uploading sensitive files.
How to convert XML to JSON in three steps
- Paste your XML into the input, or click “Load sample”.
- Choose your options — type inference, force arrays, and whether to keep or ignore attributes.
- Convert and export — copy the JSON or download it as
data.json.
Attributes, arrays, and namespaces handled properly
XML has features JSON does not, so handling them well matters.
Attributes are preserved under an @ prefix, mixed text goes
under #text, and repeated elements are
collected into arrays automatically — with a force-array
option for predictable output. Namespace prefixes are kept, CDATA is
read as text, and type inference converts numbers and booleans.
Concretely, this XML:
<catalog>
<book id="1" lang="en">
<title>Dune</title>
<price currency="USD">9.99</price>
</book>
</catalog> becomes:
{
"catalog": {
"book": {
"@id": 1,
"@lang": "en",
"title": "Dune",
"price": { "@currency": "USD", "#text": 9.99 }
}
}
}
Note price: it has both an attribute and text content, so the
text lands under #text rather than being silently thrown away.
Converters that drop attributes lose the currency entirely — and you do not
find out until the numbers are wrong.
The single-element array trap
This is the bug that bites almost everyone converting XML feeds. Two <book> elements produce an array. One <book> element produces a plain object. So code that
works fine against a catalogue of five books crashes the day a search
returns exactly one result — and it looks like a random production
incident rather than a conversion problem.
Force arrays fixes it: every child becomes a list, whether
there is one item or a hundred, so data.catalog.book[0] is
always valid. If you are converting an API response you will consume in
code, turn it on.
Convert XML to JSON in Python, JavaScript, or the terminal
Python (xmltodict) — the closest match to this tool's output:
import json, xmltodict
with open("data.xml") as f:
data = xmltodict.parse(f.read(), attr_prefix="@", cdata_key="#text")
print(json.dumps(data, indent=2)) xmltodict has the same single-element quirk — pass force_list=("book",) to pin specific tags as arrays.
JavaScript / Node.js (fast-xml-parser):
import { XMLParser } from "fast-xml-parser";
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: "@",
isArray: (name) => ["book", "item"].includes(name), // force arrays
});
const data = parser.parse(xmlString); Command line (yq) — quick for a one-off in a pipeline:
yq -p=xml -o=json eval data.xml > data.json Common XML to JSON problems (and fixes)
“My attributes disappeared.” Some converters ignore them
by default. Here they are kept under an @ prefix — and @id or @currency is usually the field you needed
most.
“My code breaks when there is only one record.” The single-element array trap above. Enable force arrays.
“My SOAP response has soap: prefixes everywhere.”
Namespace prefixes are preserved, so soap:Body stays soap:Body and you can navigate straight to the payload rather
than guessing at renamed keys.
“My leading zeros vanished.” Type inference turned 007 into 7. Switch inference off for lossless
string output.
“My XML will not parse.” XML is far stricter than HTML —
every tag must be closed, and & must be written &. An unescaped ampersand in a URL is the most common
cause.
Why use this XML to JSON tool?
It is fully client-side with no upload and no size cap — a real advantage over tools that send your XML to a server, and XML tends to be exactly the kind of data you do not want to upload: SOAP payloads, enterprise exports, and legacy system dumps. Need the reverse? Use the JSON to XML converter. Related: YAML to JSON, CSV to JSON, JSON formatter to tidy the output, and JSON to TypeScript to type it. Learn more in our guide on how to convert XML to JSON.
FAQ
XML to JSON, answered.
How do I convert XML to JSON online?+
Paste your XML into the converter above and press Convert to JSON. The tool parses the markup, maps elements to keys, and shows formatted JSON instantly. You can copy it or download a .json file. Everything runs in your browser, so nothing is uploaded.
How are attributes handled?+
Element attributes become keys prefixed with @ by default, so <book id="1"> becomes { "book": { "@id": 1 } }. Mixed content keeps the text under a #text key. You can also choose to ignore attributes entirely if you only need the element data.
What about repeated elements and arrays?+
Repeated child elements with the same tag are automatically collected into an array. If you need single elements to be arrays too (for predictable parsing), enable Force arrays so every child becomes a list.
Does it handle namespaces and CDATA?+
Yes. Namespace prefixes are preserved in key names (for example x:note stays x:note), CDATA sections are read as text, and comments and the XML declaration are ignored. Numeric and boolean text can be auto-converted with type inference.
Is it private, and is there a size limit?+
It is 100% client-side — unlike server-based converters that upload your file, your XML never leaves the browser. There is no file-size cap because everything is processed locally.
Why did my single-item list stop being an array?+
This is the classic XML-to-JSON trap. Repeated tags become an array, but a element that happens to appear only once becomes a plain object — so the same code breaks depending on how many records the response contained. Enable Force arrays to make every child a list, and your parsing stays predictable no matter the record count.
How do I convert a SOAP or RSS response to JSON?+
Paste the whole response and convert. SOAP envelopes keep their namespace prefixes (soap:Body stays soap:Body), so you can navigate straight to the payload. RSS and Atom feeds convert cleanly too, with repeated <item> elements collected into an array.
Why are my numbers coming out as strings?+
XML has no types — everything in a document is text. Type inference turns values that look like numbers, booleans, or null into real JSON types; switch it off if you need everything preserved exactly as written, which matters for IDs with leading zeros and version strings like 1.10.
Can XML always be converted to JSON?+
Structurally, almost always — but the mapping is not lossless in both directions. XML distinguishes attributes from elements, allows mixed content (text and elements side by side), and carries namespaces and processing instructions that JSON has no equivalent for. This converter preserves attributes with an @ prefix and mixed text under #text, which keeps round-tripping possible for most real documents.