XML to JSON
XML to JSON parses XML documents into clean, readable JSON, so SOAP responses, RSS feeds, and legacy configs become data your JavaScript can actually work with.
How to Use
- 1
Paste your XML document into the input field.
- 2
Attributes are grouped under a single "@attributes" object on their element, keeping them separate from child elements.
- 3
Click Convert to generate the JSON equivalent instantly.
- 4
Copy the JSON or download it as a .json file.
Frequently Asked Questions
What happens to XML attributes?
How do I know if something becomes an array?
Do numbers stay numbers?
How are XML namespaces handled?
What is "#text"?
What happens to empty elements?
What if my XML is malformed?
Can I convert the JSON back to XML?
Does it handle CDATA or mixed content?
Is my XML uploaded anywhere?
Generative Answer & AI Documentation
What is the XML to JSON?
The XML to JSON converter parses an XML document and writes the equivalent JSON: paste XML into the input panel, click “Convert to JSON”, and the output appears as indented JSON, ready to copy or download as data.json. The result is always wrapped in an object named after the document's root element, so converting <note>…</note> produces {"note": {…}}. Elements become keys, text becomes values, and repeated sibling elements with the same tag become a JSON array — three <item> elements become one item array. Attributes are kept under a single "@attributes" object on their element, and an element that has both attributes and text keeps the text under "#text". Leaf text is typed, not left as a string: "42" becomes the number 42, "true" and "false" become booleans, and "null" becomes null. Parsing is done by the browser's own DOMParser, entirely in your tab — nothing is uploaded, nothing is logged.
Why use XML to JSON offline?
A large part of the working internet still speaks XML: SOAP services return it, RSS feeds are written in it, enterprise systems export it, and legacy configs are stored in it. JavaScript, meanwhile, works in JSON — JSON.parse, fetch, and every modern API. Reading an XML response by eye means mentally stripping tags, tracking nesting, and guessing which repeated elements form a list. This tool does that translation in one click, and it does it locally: SOAP responses and config exports often carry internal field names, customer records, and example credentials that should never be pasted into a server-side converter. The type coercion is the other half of the value: a converter that left every value a string would hand you "4900" where your code expects 4900.
When should you use this tool?
Use it when an XML document needs to become data your code can use: a SOAP response copied from a bug report or the Network tab, an RSS feed you want to read as JSON, a legacy config file being migrated to a JSON-based system, or an API that returns XML where you expected JSON. Use it to inspect as well as to convert — pasting a 500-line SOAP response and reading the JSON tree is faster than reading the XML. Do not use it when the XML's exact text matters more than its structure: this tool reads elements, attributes, and text, but it drops comments, processing instructions, CDATA content, and text mixed in beside child elements. For the reverse trip, the JSON to XML page converts JSON back into XML.
Key Benefits
- Attributes preserved: element attributes are grouped under "@attributes", so no information is silently dropped.
- Smart leaf typing: numeric, boolean, and null leaf text becomes real JSON values instead of staying strings.
- Repeated elements become arrays automatically, so a list in XML is a list in JSON.
- Root preserved: the output is wrapped in the root element's name, so you always know which document the JSON came from.
- Real parse errors: malformed XML fails with the browser's parser error instead of producing a half-converted guess.
- Copy or download: one click copies the JSON, another saves it as data.json.
Common Use Cases
- Debugging a SOAP response: paste the response body and read the JSON tree instead of a wall of angle brackets.
- Turning an RSS or Atom feed into JSON for a script or a feed reader that expects JSON.
- Migrating a legacy XML config file into the JSON format a modern tool expects.
- Converting an XML API response into test fixtures for JavaScript tests.
- Checking what a system actually returned, field by field, when its documentation and its XML disagree.
Developer Notes & Best Practices
Parsing is the browser's DOMParser with the "application/xml" type, and malformed XML fails there — the tool shows the parser's error and produces no output, rather than guessing. The conversion then walks the document tree with four rules. First, the root element's name becomes the single top-level key, so <note> produces {"note": …}. Second, attributes are collected into one "@attributes" object whose values are always strings — even inStock="true" stays the string "true", because attributes are never type-coerced, unlike leaf text. An element with attributes and no child elements also gets a "#text" key for its text. Third, leaf text is coerced: "true" and "false" in any capitalisation become booleans, "null" becomes null, and anything that parses as a number becomes a number — "4900" becomes 4900, "3.14" becomes 3.14, and "007" becomes 7, losing its leading zero. Fourth, repeated siblings with the same tag become an array, while a single occurrence stays a single value — so the output shape depends on your data, not just on the schema. Two structural facts follow from that: a wrapper element is never unwrapped, so <items><item>…</item></items> becomes items: { item: […] }, not a bare array; and an empty element such as <note /> becomes an empty string, not null. Namespaces are not resolved: a namespaced tag keeps its prefix in the key, so soap:Envelope stays “soap:Envelope”. What the walk does not read: text mixed in beside child elements is dropped, text inside CDATA sections is dropped (only plain text nodes are read), and comments and processing instructions are ignored. Whitespace-only text between elements is ignored too, which is what keeps the output clean.
How each XML construct becomes JSON
| XML | JSON | Note |
|---|---|---|
| <note>…</note> | {"note": …} | Root element name becomes the top-level key |
| <item>Milk</item> × 3 | "item": ["Milk", …] | Repeated siblings become an array |
| <item>Milk</item> × 1 | "item": "Milk" | A single occurrence stays a single value |
| id="284" | "@attributes": {"id": "284"} | Attributes grouped; values always strings |
| <price>4900</price> | "price": 4900 | Numeric leaf text becomes a number |
| <active>true</active> | "active": true | "true" / "false" (any case) become booleans |
| <note /> | "note": "" | An empty element becomes an empty string |
| <name id="1">Bag</name> | {"@attributes": {"id": "1"}, "#text": "Bag"} | Text beside attributes lives under "#text" |
| Text inside CDATA | (dropped) | Only plain text nodes are read |
| Text beside child elements | (dropped) | Mixed content keeps the elements, loses the loose text |
- Check whether a value is an array or a single value before writing code against it: one <item> produces a string, two produce an array, and your code must handle both.
- Watch for values that look numeric but are identifiers: "007" becomes 7 and a ZIP code loses its leading zero — restore such fields to strings in the JSON before importing it anywhere strict.
- Remember attributes are always strings: id="284" and inStock="true" under "@attributes" are text, not a number and a boolean — cast them in your code if you need real types.
- When the output surprises you, look at the wrapper elements first: <items><item> becomes items: { item: [...] }, and the extra level is correct, not a bug.
- Keep the original XML until the JSON has been checked: the conversion drops comments, CDATA, and mixed-content text, so it is not a lossless archive of the document.
Common Mistakes
- Expecting the wrapper to disappear: <items><item>Milk</item></items> becomes items: { item: [...] } — the <items> level is kept, and the array is one level down from where most people look first.
- Writing code that assumes a field is always an array: one occurrence produces a single value, two produce an array, so the shape changes with the data — normalise it in your code.
- Expecting "007" or a ZIP code to stay a string: leaf text that parses as a number becomes a number, and the leading zero is gone — restore it as a string if it is an identifier, not a quantity.
- Expecting attributes to be coerced like leaf text: an attribute value is always a string under "@attributes", so inStock="true" is the text "true", not the boolean true.
- Pasting XML with two root elements, or a fragment with no root at all, and wondering why it fails: an XML document has exactly one root, and the parser rejects anything else.
- Expecting CDATA content to appear in the output: text inside <![CDATA[…]]> is dropped, because the converter only reads plain text nodes — move the text out of CDATA first.
Limitations
The output shape depends on the data: a single element stays a single value and two become an array, so the same feed can produce different shapes on different days — code that consumes the output must handle both. Leaf text is coerced by guessing: "007" becomes 7, "1e3" becomes 1000, and a product code that happens to look numeric loses its leading zeros. Attribute values are never coerced — they stay strings even when they read as numbers or booleans. Text inside CDATA sections is dropped entirely, text mixed in beside child elements is dropped, and comments and processing instructions are ignored, so the conversion is not lossless. Namespaces are not resolved: a prefixed tag keeps its prefix as part of the key, and two different namespaces using the same prefix will collide. Malformed XML fails outright with the browser's parser error and no partial output. Conversion runs only when you click “Convert to JSON”, there is no file upload, and very large documents can be slow in a browser tab.
Structured Input/Output Example
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<items>
<item>Milk</item>
<item>Bread</item>
<item>Eggs</item>
</items>
</note>{
"note": {
"to": "Tove",
"from": "Jani",
"heading": "Reminder",
"body": "Don't forget me this weekend!",
"items": {
"item": [
"Milk",
"Bread",
"Eggs"
]
}
},
}Related Tools
JSON to XML
JSON to XML converter: turn JSON into well-formed XML in one click — for SOAP services, enterprise middleware, RSS feeds, and configs. Free, offline.
CSV to JSON
CSV to JSON converter: turn spreadsheets into JSON arrays instantly, with smart type inference ("42" → 42) and custom delimiter support. Free, offline.
YAML to JSON
YAML to JSON converter: turn YAML configs into valid JSON instantly — paste a Kubernetes manifest or docker-compose file. Free, offline, nothing uploaded.