XML to JSON Converter Online (Free, Private)
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Convert XML to JSON in your browser. Attributes become @keys, repeated elements become arrays, and numbers and booleans can be typed. Nothing is uploaded.
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the XML to JSON converter
- Paste your XML into the box.
- Choose your options:
- Convert numbers and true/false: turns text like 29.99 and true into real JSON numbers and booleans instead of strings.
- Indent: 2 spaces, 4 spaces, or minified on one line.
- Attribute prefix: the characters added to attribute names, @ by default.
- Copy the JSON with the Copy button.
The XML to JSON converter works entirely in your browser. Your data is never uploaded, which matters for files containing customer records, configuration or other private information.
How XML maps to JSON
XML and JSON represent data differently, so converting between them follows a set of rules. The XML to JSON converter uses a widely used convention:
- The root element becomes the single top-level key.
- Child elements become keys inside their parent's object.
- Repeated elements with the same name become an array.
- Attributes become keys with a prefix, such as @id.
- Elements that contain only text become simple values.
- Elements with both attributes or child elements and text keep their text under a #text key.
- Empty elements become null when types are converted, or an empty string otherwise.
For example, this XML:
<catalog>
<book id="bk101" lang="en">
<title>Writing for the Web</title>
<price>29.99</price>
<inStock>true</inStock>
</book>
<book id="bk102">
<title>Data & Design</title>
<price>15</price>
<inStock>false</inStock>
</book>
</catalog>
becomes:
{
"catalog": {
"book": [
{
"@id": "bk101",
"@lang": "en",
"title": "Writing for the Web",
"price": 29.99,
"inStock": true
},
{
"@id": "bk102",
"title": "Data & Design",
"price": 15,
"inStock": false
}
]
}
}
Notice that the two book elements became an array, the attributes gained an @ prefix, the & entity was decoded to &, and the prices and stock values became a number and a boolean.
What the converter handles
The XML to JSON converter includes its own XML parser, which handles:
- Elements and attributes, with single or double quotes.
- Self-closing tags, such as
. - Character entities, including <, >, &, ", ' and numeric references like © and ©.
- CDATA sections, whose content is kept as text without decoding.
- Comments, processing instructions and the XML declaration, which are skipped.
- A DOCTYPE, which is skipped.
If the XML isn't well-formed, for example if a closing tag doesn't match its opening tag, the converter shows an error with the line number so you can fix it.
Arrays: the one tricky part
XML has no separate concept of a list, so the converter decides whether something is an array by counting: if an element name appears more than once under the same parent, it becomes an array. That means the shape of the JSON can change depending on the data. A catalogue with two books gives "book": [ … ], but a catalogue with one book gives "book": { … }. If you're writing code that reads the JSON, handle both cases, or check whether the value is an array before looping over it.
Numbers and booleans
XML stores everything as text, so 29.99 and true are strings until something interprets them. With "Convert numbers and true/false" ticked, the XML to JSON converter turns plain numbers and the words true and false into JSON numbers and booleans. Values that only look like numbers but shouldn't be converted, such as phone numbers, postcodes or IDs with leading zeros like 00123, are left as strings, because they don't match the pattern for a plain number. Very long numbers are also kept as strings to avoid losing precision. Untick the option to keep every value as a string.
Why convert XML to JSON?
XML is still common in enterprise systems, RSS and Atom feeds, sitemaps, office documents, SOAP web services, banking and government data exchange, and many configuration files. JSON has become the default for web APIs and JavaScript applications, because it's lighter and maps directly onto objects and arrays in most programming languages. Converting XML to JSON lets you work with older data in modern tools, inspect a feed quickly, or prepare data for a JavaScript app or NoSQL database.
Who uses an XML to JSON converter
Developers use it to integrate with XML-based APIs and feeds, and to inspect XML data in a more familiar shape. Data analysts use it to prepare XML exports for tools that prefer JSON. SEO specialists use it to inspect sitemaps and feeds. Students use it to learn how the two formats relate.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. That is the whole job of DeepRit: a PPC-only agency that sets up and runs Google Ads accounts so every click is accounted for. You keep full ownership of your account, get a written report every week, and can stop at any time. See our pricing or ask for a free audit.
Namespaces
XML namespaces add prefixes to element and attribute names, such as xs:element or atom:link. The XML to JSON converter keeps these prefixes as part of the key names, so atom:link becomes "atom:link". Namespace declarations like xmlns:atom appear as attributes with the @ prefix. That keeps all the information, though you may want to strip prefixes in your own code if you don't need them.
Mixed content
Some XML mixes text and elements together, like
Formatting the result
The 2-space and 4-space options produce readable, indented JSON. Choose "Minified" for the smallest output, for example to paste into a configuration value or send over a network. To reformat or validate JSON later, use the JSON formatter. To tidy the XML first, use the XML formatter. For spreadsheets, the JSON to CSV converter turns arrays of records into rows.
Common mistakes
- Expecting single items to be arrays. Only repeated elements become arrays.
- Converting codes with leading zeros to numbers. The converter keeps them as strings, but check any custom processing you do afterwards.
- Pasting HTML instead of XML. HTML isn't always well-formed XML, for example tags like
without a closing tag. - Forgetting that XML allows only one root element.
Converting RSS feeds and sitemaps
RSS feeds and XML sitemaps are two of the most common XML files people want to inspect. An RSS feed has a
Choosing an attribute prefix
The @ prefix is a common convention, but some tools and libraries expect a different one, such as an underscore or a dash, or no prefix at all. Change the attribute prefix in the XML to JSON converter to match the format your code expects. If you remove the prefix entirely, be aware that an attribute and a child element with the same name would clash, and the later one would overwrite the earlier one.
Converting large files
Because the XML to JSON converter runs in your browser, it can handle quite large files, limited mainly by your device's memory. For very large files, such as multi-gigabyte data exports, a streaming parser in a programming language is a better choice, because it can process the file piece by piece without loading it all at once. For everyday files, such as API responses, feeds and configuration files, the browser is fast and keeps your data private.
Converting back to XML
Converting JSON back to XML is possible with the same conventions in reverse, but XML has features JSON lacks, such as the order of mixed text and elements, comments and processing instructions, so a round trip may not reproduce the original file exactly. If you need to edit XML, it's usually best to edit the original and only convert to JSON for reading or processing.
Sources and further reading
- W3C: Extensible Markup Language (XML) 1.0, the official XML specification.
- JSON on Wikipedia: the JSON format and its history.
- IETF: RFC 8259, the JSON data interchange format standard.
Frequently asked questions
How do I convert XML to JSON?
Paste your XML into the XML to JSON converter and copy the JSON it produces.
How are attributes converted?
They become keys with a prefix, @ by default, such as "@id": "bk101".
Why is one element an array and another an object?
Elements that appear more than once under the same parent become arrays; single elements stay as objects or values.
Is my data uploaded?
No. The conversion runs entirely in your browser.
Can it convert numbers and booleans?
Yes. Tick the option to turn plain numbers and true/false into JSON types.
Is the XML to JSON converter free?
Yes. It's free, needs no sign-up, and works in your browser.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.