Convert XML to JSON
Turn an XML document into JSON with attributes and arrays.
- Nothing is uploaded
- Free · no account
- Tested on 400k-row files
Reference
XML to JSON: how it works
The tool is above. Below: a short overview, optional step-by-step detail, honest browser limits, and answers to common questions.
Last updated 2 min read
About this tool
PrivateCSV converts an XML document to JSON as you paste it. Each element becomes a key, attributes become keys starting with @, repeated elements become arrays, and text inside an element with attributes goes under #text. Numbers and true/false can be detected, while values such as 00123 stay text. Invalid XML is reported with its line and column. The XML is parsed in your browser and never uploaded.
Read the step-by-step guideHow-to, example and use cases (~2 min)
How to convert XML to JSON
- Paste the XML in the left box, or open an .xml file.
- The JSON appears on the right; an error message gives the line and column if the XML is not well-formed.
- Choose how attributes are named (@id, _id or id) and whether numbers and booleans are detected.
- Copy the JSON or download it as a .json file.
Example
An order with attributes and a repeated element.
<order id="7">
<item>Lamp</item>
<item>Mug</item>
<total currency="EUR">24.90</total>
</order>{
"order": {
"@id": 7,
"item": [
"Lamp",
"Mug"
],
"total": {
"@currency": "EUR",
"#text": 24.9
}
}
}When you need it
- SOAP and legacy APIs
- Turn an XML response into JSON to read it more easily, or to feed it to a JavaScript app, a no-code tool or a database that stores JSON.
- Feeds and exports
- RSS feeds, sitemaps, product feeds and accounting exports come as XML. As JSON they are easier to filter with jq or to load in Python and JavaScript.
- Config files
- Convert Maven, .NET or Android XML settings to JSON to compare them or move them to a JSON-based tool.
Conversion rules
- The root element becomes the single top-level key.
- An element with only text becomes that text (or a number or boolean if detection is on); an empty element becomes null.
- Attributes become keys with the chosen prefix, @ by default.
- An element that appears several times in the same parent becomes an array; tick Always use arrays to get arrays for every child element, so the shape stays the same across files.
- Text next to attributes or child elements goes under #text. CDATA is read as text; comments and processing instructions are skipped.
- Namespace prefixes are kept in the names, such as g:price.
Browser and file limits (not a trial)
These are technical limits of running in your browser—device memory, encoding and what this tool does not do. They are not a free trial, account quota or paid plan. There is no subscription.
- The text box holds up to 20 MB.
- Mixed content (text interleaved with elements, as in XHTML paragraphs) is simplified: all the text of an element is joined under #text.
- The order of different child elements is not kept, since JSON objects are unordered; repeated elements keep their order in their array.
Frequently asked questions
How do I convert XML to JSON?
Paste the XML in the box above or open the file. The JSON appears at once, with attributes as @ keys and repeated elements as arrays. Copy it or download it.
How are XML attributes represented in JSON?
As keys with a prefix, @ by default: <total currency="EUR"> becomes "@currency": "EUR". You can choose _ or no prefix in the options.
Why is a single element an object but several elements an array?
XML does not say whether an element can repeat, so the converter makes an array only when it sees the element more than once. If your code expects arrays every time, tick Always use arrays for child elements.
Can I convert XML to a table instead of JSON?
Yes. For records that should become rows, use XML to CSV or XML to Excel: they flatten each repeated element into one row with one column per field.
Related tools
Go further
Your files never leave your device
PrivateCSV runs this tool in your browser. No upload, no account, no trial and nothing to install.