XML to JSON

Turn an XML document into JSON you can work with in code, with attributes kept as @-prefixed keys.

or drop them here · files stay on your device
We count formats and sizes. Filenames stay private unless you opt in.

Pretty-print the output
Processed on this device
  • Runs on your device
  • No sign-up or watermark
  • No fixed file size cap

The short answer

To convert XML to JSON, choose one or more .xml files and run the converter. The browser’s own XML parser reads each file, attributes become keys starting with @, and repeated elements become arrays. Nothing is uploaded. Malformed XML is rejected with the parser’s error rather than half-converted.

How to convert an XML file to JSON

  1. STEP 1

    Choose XML files

    Select one or more .xml files, such as an RSS feed, a sitemap or a SOAP response. They stay on your device.

  2. STEP 2

    Set the layout

    Pretty-print the output is on by default; turn it off for compact JSON.

  3. STEP 3

    Convert to JSON

    A file that is not well-formed stops with the first line of the parser’s error, naming the file.

  4. STEP 4

    Copy or download

    Copy the JSON from the preview or download it; several files are bundled as a ZIP.

Why there is no single right way to turn XML into JSON

XML has things JSON does not: attributes, text mixed with child elements, namespaces and element order that can carry meaning. Every converter picks a convention. This one follows a common one: attributes become keys prefixed with @, an element that holds only text becomes a plain string, and an element that appears more than once becomes an array.

The trade-off of that convention is shape. A <book> that appears once is an object, and two of them are an array, so code reading the JSON should be ready for either.

What survives, and what does not

Each file is parsed with DOMParser as application/xml, so well-formedness is checked strictly. The root element becomes the single top-level key. For each element, attributes are copied as @name keys and children are grouped by tag name. A leaf with attributes keeps its text under #text; a leaf without attributes becomes its text directly. All values are strings, and surrounding whitespace is trimmed.

What you keep

Element nesting and every attribute, as @-prefixed keys

Repeated sibling elements, collected into arrays in document order

Text inside leaf elements, including CDATA content

What you lose

Text that sits beside child elements (mixed content) is dropped, so this suits data XML better than prose markup

Comments and processing instructions

Types: numbers and booleans stay strings

Namespaces are not resolved; prefixed tag names such as ns:item are kept as written

Honest limits are published on every tool page. If a tool cannot do something well, it says so here rather than letting you find out after the download.

XML to JSON at a glance

InputXML
OutputJSON
AttributesKept as @name keys
ParserBrowser built-in DOMParser
BatchYes, several files at once
Runs onYour device, in the browser

If something goes wrong

It says the file is not well-formed XML

Look for an unclosed tag, an unescaped & (it must be &amp;) or a second root element. HTML that is not XHTML usually fails here too.

Some text is missing from the output

Text that sits next to child elements, as in <p>Hello <b>you</b></p>, is not kept. The converter is built for data-style XML where text lives in leaf elements.

XML to JSON questions

How are XML attributes shown in JSON?

As keys with an @ in front, so <item id="7"> becomes {"@id": "7"}. If that element also has text, the text goes under #text.

Why is one element an object and another an array?

An element that appears once becomes an object or string; one that repeats under the same parent becomes an array. Code reading the result should handle both.

Are numbers converted to numbers?

No. XML text has no types, so every value is a string. Convert the fields you need in your own code.

Can I convert an RSS feed or sitemap to JSON?

Yes. Save the feed or sitemap as an .xml file and convert it. Items and url entries become arrays you can loop over.

Is the XML uploaded?

No. The browser’s own parser reads the file in your tab, so SOAP responses and exports with personal data stay on your machine.

One of 153 file tools and planned additions. Built and tested by Arin Prajapati, last checked against the code on . canonical: https://damnfiles.com/xml-to-json
Analytics preferences

Help us understand which tools and file types people use. File contents always stay on your device.

Filename sharing is optional and off by default. Names can contain personal information. Changes apply to future events; disabling sharing does not delete earlier records.

Read our privacy policy