Summary
An XML to JSON converter rewrites an XML document as JSON, so JavaScript, REST APIs and most modern tools can read it. To convert XML to JSON free and privately here, paste your XML into XML Input, or click Open XML File or Load Sample, choose an Attribute Style, click Convert to JSON, then click Copy or Download JSON. The tool runs in your browser and nothing is uploaded; you can check the Network tab in DevTools.
XML and JSON do not map one to one, so the converter follows fixed rules. The root element becomes the single top-level key, attributes become "@name" keys or an "_attributes" object, repeated elements become arrays, text beside attributes or child elements goes in "#text", and every value stays a string unless you tick Convert numbers and true/false. Only well-formed XML converts; there is no DTD or XSD validation.
Table of Use: XML In, JSON Out
| XML construct | Setting | JSON result |
|---|---|---|
<book id="1"> | Attribute Style: @ prefix (default) | "@id": "1" |
<book id="1"> | Attribute Style: _attributes object | "_attributes": { "id": "1" } |
<price currency="USD">10.99</price> | Default | "price": { "@currency": "USD", "#text": "10.99" } |
<tag>a</tag><tag>b</tag> | Default | "tag": ["a", "b"] |
<title>Gatsby</title> | Always use arrays for child elements | "title": ["Gatsby"] instead of "title": "Gatsby" |
<year>1925</year> | Convert numbers and true/false | "year": 1925; without the option "year": "1925" |
<p>Hello <b>world</b> again</p> | Default | "p": { "b": "world", "#text": "Hello again" } |
<e/> | Default | "e": "" |
<soap:Body> under xmlns:soap="u" | Default | "soap:Body" key and "@xmlns:soap": "u" |
| A tag that is never closed | Default | An Invalid XML panel with the line, column and the parser's message |
Worked example: with Load Sample, the three-book library becomes JSON in which book is an array of 3 objects; the tool reports 19 elements (including the root), 9 attributes and an output of 1.00 KB when pretty-printed.
Features
- Shape controls. Attribute Style (@ prefix or _attributes object), Output Style (Pretty print with 2 spaces, or Compact on one line) and four checkboxes: Ignore attributes, Ignore CDATA sections, Convert numbers and true/false, and Always use arrays for child elements. Changing an option updates the result at once.
- No overwritten data. If an element has attributes and a child named _attributes, its attributes are written as @ keys and a note tells you which element.
- Careful number detection. With the option on, a value is turned into a number only when the JSON number reads exactly like the text, so IDs and version numbers are not corrupted.
- Files. Open XML File accepts .xml, .rss, .atom, .svg, .xsd, .wsdl, .kml and .gpx; you can also drop a file on the input. The byte order mark or the encoding named in the XML declaration (for example ISO-8859-1 or UTF-16) is respected. A download is named after the file (catalog.xml becomes catalog.json) or converted.json for pasted XML.
- Statistics and errors. Cards show Elements, Attributes and Output Size. Malformed XML is reported with its line and column.
Limits: siblings are grouped by name in order of first appearance, so <a/><b/><a/> becomes an a array followed by b, and the order across different names is not kept. Comments, processing instructions and the XML declaration are dropped, namespace URIs are not resolved, and the conversion is one way. To turn JSON back into XML use the JSON to XML converter. If the tool reports invalid XML, the XML validator and the XML formatter help you find the fault.
How to Use the XML to JSON Converter
- Paste your XML into XML Input, drop a file on it, or click Open XML File. Load Sample fills in an example.
- Choose an Attribute Style and an Output Style, and tick Ignore attributes, Ignore CDATA sections, Convert numbers and true/false or Always use arrays for child elements if you need them.
- Click Convert to JSON. Opening a file or loading the sample converts at once. If the XML is invalid, read the Invalid XML panel and fix the line it names.
- Check JSON Output and the Elements, Attributes and Output Size cards. After editing the XML, click Convert to JSON again; option changes apply immediately.
- Click Copy or Download JSON. Clear All empties the page.
Who Can Use It
Developers moving a SOAP or legacy API response to a REST client, front-end developers reading an RSS or Atom feed in JavaScript, and engineers migrating XML configuration to JSON all need this conversion. Analysts can turn XML exports into JSON and then into a spreadsheet with the JSON to CSV converter. Tidy the result with the JSON formatter, check it with the JSON validator, or shrink it with the JSON minifier.
Working with other formats? Convert configuration files with the YAML to JSON converter or go back with JSON to YAML, and turn spreadsheets into JSON with the CSV to JSON converter. An XML sitemap can be read here too, and you can build a new one with the sitemap generator.
FAQs
How do I convert XML to JSON online?
Paste your XML into XML Input, or click Open XML File or Load Sample. Pick an Attribute Style, click Convert to JSON, then click Copy or Download JSON. Open XML File and Load Sample convert at once. The tool runs in your browser and nothing is uploaded; you can check the Network tab in DevTools.
How are XML attributes converted to JSON?
Attribute Style offers two choices. With the @ prefix style, id="1" becomes "@id": "1" next to the child elements. With the _attributes object style, an element's attributes are grouped in an "_attributes" object; if that element also has a child named _attributes, the @ style is used for it so nothing is overwritten. Ignore attributes leaves them out.
Why is one element an object and another an array?
An element that appears once becomes a single value and an element that repeats becomes an array, which mirrors the XML but changes the shape when a list happens to have one item. Tick Always use arrays for child elements to get an array for every child, so code that reads the JSON can always loop.
Are numbers and true/false converted?
Only if you tick Convert numbers and true/false. XML has no data types, so by default every value stays a string. With the option on, 1925, 10.99 and true become JSON numbers and booleans, but a value becomes a number only when the JSON number reads exactly like the XML text, so 007, 1.10, 1e5, -0 and very long IDs stay strings.
What happens to namespaces, CDATA and mixed content?
Namespace prefixes stay in the names, so <soap:Body> becomes a "soap:Body" key and xmlns:soap becomes an attribute; URIs are not resolved. CDATA text is kept exactly unless you tick Ignore CDATA sections. In mixed content such as <p>Hello <b>world</b> again</p>, the text pieces are joined with a space as "#text": "Hello again". Comments are dropped.
What if my XML is invalid?
The tool uses your browser's XML parser, which accepts only well-formed XML. An unclosed tag, an unquoted attribute or an HTML entity such as produces an Invalid XML panel with the parser's message, line and column. It checks well-formedness only; it does not validate against a DTD or XSD schema.
Is there a file size limit?
There is no fixed limit. Conversion happens in your browser, so the practical limit is your device's memory. The JSON Output box shows at most the first 2,000,000 characters of a very large result; Copy and Download JSON always include the complete JSON. A document nested too deeply for the browser asks you to split it.
Is my XML uploaded anywhere?
No. This tool runs in your browser and nothing is uploaded; you can check the Network tab in DevTools while you convert. Parsing and conversion are done by JavaScript on the page, and a file you open is read locally by your browser, so your XML stays on your device.