XML to JSON Converter: Free, No Sign-Up

XML to JSON

Convert XML data to JSON format. Paste text, upload a file, or drag & drop.

An XML to JSON converter turns XML markup into JSON objects and arrays so web apps, APIs and scripts can read the data. With this free tool you paste XML or upload a file, choose a JSON layout, and get formatted output plus key count, depth and size stats, ready to copy or download.

What Is XML to JSON Conversion?

XML to JSON conversion rewrites data stored in XML tags as JSON keys and values. XML wraps each piece of data in opening and closing tags, and it can add attributes and namespaces. JSON uses curly braces for objects, square brackets for arrays and simple key-value pairs. Both formats describe nested data, so a child element in XML becomes a nested object in JSON.

How XML Maps to JSON

JSON has no attributes, so every converter follows a convention. This tool uses these rules:

  • An element that holds only text becomes a key with a text value.
  • Sibling elements that repeat the same name become an array.
  • An attribute becomes a key that starts with an underscore, such as _category.
  • When an element has both attributes and text, the text is stored under a key named __text.
  • Namespace prefixes such as dc:title are removed by default, leaving title.

XML vs JSON: Which Is Better?

Neither format is better in every case. JSON is shorter and maps directly to objects in JavaScript, Python and most other languages, which is why REST APIs favor it. XML supports attributes, comments, schemas and mixed text and tags, so it remains common in RSS and Atom feeds, sitemaps, SVG files, SOAP services and many configuration files. You convert from XML to JSON when the system that receives the data expects JSON.

How to Use the XML to JSON Converter

You can convert a document in six steps, and the whole process takes a few seconds.

  1. Choose the Paste XML tab and enter your markup in the XML Data box, or choose Upload File and drag and drop an XML file or click to browse. The file picker accepts .xml, .xsl, .xslt, .svg, .rss, .atom and .txt files. Use Remove file to clear an upload.
  2. Open the JSON Format menu and pick Pretty Print (2 spaces), Pretty Print (tabs) or Minified.
  3. Tick Remove top-level root element if you want the output to start at the root's children instead of the root name.
  4. Leave Strip namespace prefixes checked to drop prefixes, or clear it to keep names such as dc:title exactly as written.
  5. Click Convert to JSON. The Keys, Max Depth and JSON Size figures appear with a Structure Preview and the JSON Output.
  6. Click Copy to put the result on your clipboard or Download to save it as a file.

Not sure what to paste? Click Sample to load a small bookstore document, and Reset to start over.

Which JSON Format Should You Pick?

OptionBest forTrade-off
Pretty Print (2 spaces)Reading and sharingLarger text
Pretty Print (tabs)Projects that indent with tabsLarger text
MinifiedAPI payloads and storageHard to read

Worked Example: Converting a Small Bookstore

Here is a short document with two books, one of which carries attributes on its title: <bookstore><book category="fiction"><title lang="en">The Great Gatsby</title><year>1925</year></book><book category="science"><title lang="en">A Brief History of Time</title><year>1988</year></book></bookstore>

With the default settings, the first book converts to this shape: {"_category":"fiction","title":{"_lang":"en","__text":"The Great Gatsby"},"year":"1925"}. The two book elements share a name, so they sit together in one array under a book key, all inside a bookstore object.

Now tick Remove top-level root element and convert again. The output starts with the book array directly, one level shallower, so Max Depth drops by one. That is handy when your code already knows it is reading a bookstore and does not need the wrapper.

How to Read and Act on the Results

The results panel gives you three numbers, a collapsible tree and the final JSON, and each one tells you something you can act on.

  • Keys: the total number of keys in the output. A count far higher than you expected usually means attributes or repeated elements were converted into many separate keys.
  • Max Depth: how many levels of nesting the data has. Depth beyond five or six levels is awkward to work with. Remove the root element, or flatten the structure in your own code.
  • JSON Size: the size of the output text. Switch between pretty and minified to see how much whitespace adds. Minified output is the better choice for payloads you send over a network.
  • Structure Preview: a tree you can collapse to scan the hierarchy quickly before reading the raw text.

Common Surprises in the Output

  • Keys that start with an underscore. These are your XML attributes. Rename them in your code if your application expects plain names.
  • Numbers inside quotes. XML stores everything as text, so a value like 1925 can appear as a string. Convert it to a number in your own code where you need math or sorting.
  • An object where you expected an array. A list that contains only one item can come out as a single object. Write code that accepts both shapes before you loop over it.
  • Messages in place of output. "Please enter or upload XML data first" means the input was empty. "Invalid XML" means the document is not well formed, so fix the markup and convert again.

Who Uses an XML to JSON Converter?

Anyone who receives data in XML but needs it in JSON benefits, and the most common situations are practical ones.

  • Web developers who consume a SOAP response or a legacy export in a JavaScript front end and want to see the JSON shape before writing parsing code.
  • SEO specialists who want to inspect an RSS feed, an Atom feed or a sitemap as JSON. If you still need to build the sitemap itself, the XML sitemap generator creates one from your site URL.
  • Data analysts who convert XML to JSON and then continue with the JSON to CSV converter to open the records in a spreadsheet.
  • DevOps and configuration work where a team moves settings between formats. The YAML and JSON converter covers the next hop if you need YAML.
  • Students comparing the same data in both formats to understand how markup maps to objects.

Best Practices and Troubleshooting Tips

Most failed conversions come from malformed XML, so a few habits prevent nearly all of them.

  • Keep one root element. A well-formed document has exactly one outermost element. Two top-level elements side by side cause an Invalid XML message.
  • Close every tag and escape special characters. A bare ampersand must be written as &amp;, and a less-than sign inside text as &lt;.
  • Tidy messy markup first. If you cannot spot the error, run the document through the XML formatter to see the indentation and find the unclosed tag.
  • Think before stripping namespaces. Removing prefixes gives cleaner keys, but two elements such as a:id and b:id would then share one name. Clear the Strip namespace prefixes box when the prefixes carry meaning.
  • Check text files. A .txt upload works only when the text inside is real XML. A stray character before the first tag can break it.
  • Validate the JSON afterward. Paste the output into the JSON formatter and validator if you plan to ship it to an API, and confirm it parses cleanly.
  • Use the tool as a preview for code. If you later convert XML inside a Python, Java or C# project, compare your code's output with this result to confirm that attributes and arrays land where you expect.

Limitations to Keep in Mind

This converter changes the format in one direction only, from XML to JSON, and it cannot turn JSON back into XML. Because JSON has no attributes, the underscore and __text naming is a convention. Other converters can name those keys differently, so do not assume that output from two converters will match.

Mixed content, where text sits between child tags, may not keep its exact order. Numbers and dates stay as text, and very large documents can take longer to convert, so split a huge file into smaller parts if the page slows down. Always review the Structure Preview before relying on the result in production.

Paste your markup into the XML Data box above, press Convert to JSON, and you will have clean, correctly nested JSON to copy or download in seconds. For more utilities of this kind, browse the web developer tools collection.

Frequently Asked Questions

What does an XML to JSON converter do?
An XML to JSON converter rewrites XML tags, attributes and text as JSON objects, arrays and values. This tool keeps the nesting of your document, so a child element becomes a nested object and repeated elements become an array you can use in APIs and scripts.
How do I convert an XML file to JSON?
Open the Upload File tab, drag and drop your file or click to browse, then press Convert to JSON. The picker accepts .xml, .xsl, .xslt, .svg, .rss, .atom and .txt files. You can also paste XML into the XML Data box instead.
What happens to XML attributes when converting to JSON?
Attributes become JSON keys that start with an underscore. For example, lang="en" turns into _lang with the value en. If the element also has text, that text is stored under a key named __text next to the attribute keys.
Why does the converter say Invalid XML?
The message means your document is not well formed. Common causes are an unclosed tag, two top-level elements, or a bare ampersand that should be written as &. Fix the markup, or tidy it with the XML Formatter, and convert again.
Is XML or JSON better for APIs and data exchange?
JSON is usually the better fit for web APIs because it is shorter and maps directly to objects in most languages. XML suits documents that need attributes, comments or schemas, such as feeds and sitemaps. Choose the format your receiving system expects.
Is the XML to JSON converter free, and do I need to sign in?
The XML to JSON converter is free and does not require sign-in. You can paste XML or upload a file, choose Pretty Print (2 spaces), Pretty Print (tabs) or Minified, then copy the result or download it as a file.
Recommended

Explore VPN options

A VPN changes your network exit. It does not guarantee anonymity.

Hide Your IP Encryption Network coverage
Protect My IP Now