XML to JSON Converter
Turn an XML document into JSON, keeping attributes, repeated elements and text content in a predictable structure.
Processed locally in your browser/ Your data stays in your browser.
What is XML to JSON Converter?
XML and JSON model data differently, so every converter has to pick conventions. Here an element becomes a key, repeated sibling elements become an array, attributes become keys starting with a prefix (default @_), and the text of an element that also has attributes or children goes into a #text key.
The conversion uses fast-xml-parser with safe settings. Values stay strings by default so that codes like 007 do not lose their zeros; you can opt in to number and boolean conversion. The XML declaration and processing instructions are dropped, CDATA is merged into text, and the five predefined entities plus numeric character references are decoded. Documents that declare entities are rejected to prevent “billion laughs” and XXE attacks.
How does it work?
- Paste your XML.
- Set the attribute prefix and the text node name, or disable attributes altogether.
- Optionally enable conversion of numbers and booleans and choose the output indentation.
- Copy or download the JSON, or Swap to convert it back with JSON to XML.
Common use cases
- Consuming a SOAP or legacy XML API from a JavaScript front end.
- Converting an RSS or sitemap file to JSON for processing.
- Inspecting an XML export with JSON tooling such as the JSON Viewer or JSONPath.
- Migrating XML configuration to JSON or YAML.
Examples
Try this input in the tool above:
<?xml version="1.0"?>
<catalog lang="en">
<book id="bk101">
<title>XML Developer's Guide</title>
<price currency="USD">44.95</price>
</book>
<book id="bk102">
<title>Midnight Rain</title>
<price currency="USD">5.95</price>
</book>
</catalog>{
"catalog": {
"book": [
{
"title": "XML Developer's Guide",
"price": {
"#text": "44.95",
"@_currency": "USD"
},
"@_id": "bk101"
},
{
"title": "Midnight Rain",
"price": {
"#text": "5.95",
"@_currency": "USD"
},
"@_id": "bk102"
}
],
"@_lang": "en"
}
}Privacy
XML to JSON Converter runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.
Limitations
XML features with no JSON equivalent are lost: comments, processing instructions and the order of interleaved text and elements (mixed content). One repeated element becomes an object, two or more become an array, so array shapes depend on the data.
Frequently asked questions
Why is my single child element an object instead of an array?
The converter cannot know the schema: one <item> becomes an object, two or more become an array. Handle both shapes in code, or use a schema-aware tool when the shape must be fixed.
Are XML entities and DOCTYPE processed?
The five predefined entities and numeric references are decoded. A DOCTYPE that declares entities is rejected with an explanation, because such documents can be used for exponential expansion or to read local files in unsafe parsers.
Are numbers converted?
Not by default: every value is a string, which is lossless. Enable “Convert numbers & booleans” to get numeric and boolean JSON values; leading-zero values such as 007 stay strings.
Related tools
JSON to XML Converter
Turn a JSON document into well-formed XML with control over the root element, attributes and formatting.
JSON & Data
XML Formatter & Beautifier
Turn compressed or messy XML into a cleanly indented document that is easy to read and review.
JSON & Data
XML Validator
Find out whether your XML is well-formed and see precisely where it breaks.
JSON & Data
JSON Formatter & Beautifier
Turn a minified or messy JSON document into readable, consistently indented text, with a precise error message if the JSON is invalid.
JSON & Data
YAML to JSON Converter
Turn YAML into strict JSON, resolving anchors, aliases and merge keys along the way.
JSON & Data
JSON to YAML Converter
Turn JSON into readable block-style YAML, with strings quoted only when necessary.
JSON & Data
JSON to CSV Converter
Paste a JSON array and get a CSV file ready for Excel or Google Sheets, with nested data flattened into columns.
JSON & Data