Skip to main content

Usevila

XML to JSON Converter

Paste or upload your XML and get clean, formatted JSON in one click. Attributes, repeated tags and nested elements are handled for you. Free, fast and private.

Everything runs in your browser. Attributes become keys that start with @, text next to attributes becomes #text, and repeated tags become arrays.

What Is an XML to JSON Converter?

An XML to JSON converter turns data written in XML (Extensible Markup Language) into JSON (JavaScript Object Notation). XML describes data with opening and closing tags, while JSON uses simple key and value pairs, arrays and nested objects. Moving from one format to the other is a very common task when you work with APIs, web apps, configuration files or data exports.

Our free online tool does the whole job in your browser. Paste your XML or upload an .xml file and clean, formatted JSON appears instantly. You can choose the indentation, keep or drop attributes, and decide whether numbers and true or false values should become real JSON types.

How to Convert XML to JSON

  1. Paste your XML into the input box, or click Upload to load an .xml file. Click Sample if you only want to see how it works.
  2. Choose the indentation: 2 spaces, 4 spaces, tab or minified.
  3. Tick or untick Keep attributes and Convert numbers & booleans to match what your project needs.
  4. The JSON output updates as you type. Click Convert to refresh it, Copy to copy it, or Download to save a .json file.

If your XML has a mistake, the tool shows the line and column of the problem so you can fix it quickly.

How XML Is Mapped to JSON

XML and JSON do not match one to one, so every converter follows a set of rules. This tool uses the common convention below.

XMLJSON result
<name>Maya</name>"name": "Maya"
<price currency="USD">12.50</price>"price": { "@currency": "USD", "#text": 12.5 }
<book id="1"/>"book": { "@id": 1 }
Two <book> tags side by side"book": [ { ... }, { ... } ]
<note/> (empty element)"note": null
CDATA sectionPlain string value

Attributes, Text and Repeated Elements

Three cases cause most of the confusion when people convert XML to JSON.

  • Attributes: JSON has no attributes, so each one becomes a key with an @ prefix, for example @id. Untick Keep attributes if you do not need them.
  • Text next to attributes: when an element has both attributes and text, the text is stored under the key #text.
  • Repeated elements: two or more siblings with the same name become a JSON array. A single element becomes a plain object, so if your code always expects a list, wrap single values in an array after the conversion.

Why Convert XML to JSON?

  • APIs and web apps: modern REST APIs and JavaScript frameworks use JSON natively, and JSON.parse() reads it in one line.
  • Smaller and easier to read: JSON has no closing tags, so the same data is usually shorter and quicker to scan.
  • Legacy data: SOAP responses, RSS feeds, sitemaps and old exports are often XML and need a modern format before you can use them.
  • NoSQL databases: tools like MongoDB store JSON-style documents, so XML data must be converted before import.

XML vs JSON: Quick Comparison

FeatureXMLJSON
SyntaxOpening and closing tagsKey and value pairs
Data typesEverything is text unless a schema says otherwiseString, number, boolean, null, array, object
AttributesSupportedNot supported
CommentsSupportedNot supported
Typical sizeLarger because of closing tagsUsually smaller
Common useSOAP, RSS, sitemaps, documentsREST APIs, web and mobile apps

Common XML Errors and How to Fix Them

  • Unclosed or mismatched tags: every opening tag needs a matching closing tag in the right order.
  • More than one root element: valid XML has exactly one root element that wraps everything else.
  • Unescaped characters: write &amp; for & and &lt; for < inside text.
  • HTML entities: names like &nbsp; are not defined in XML. Use the plain character or a numeric entity instead.
  • Unquoted attributes: attribute values must always be wrapped in quotes.
  • Spaces before the declaration: if you use an XML declaration, it must be the very first thing in the file.

Who Uses an XML to JSON Converter?

Developers use it to feed old XML services into modern front ends. QA engineers and API testers use it to compare responses in a readable format. Data analysts use it to prepare feeds and exports for scripts and databases. SEO specialists use it to inspect sitemaps and product feeds, and students use it to learn how both formats work.

Working with other formats too? Try our JSON to YAML converter or the CSV to XML converter.

Is It Safe to Paste My XML Here?

Yes. The conversion runs entirely in your browser with JavaScript. Your XML is not uploaded, stored or sent to any server. As a general habit, still avoid pasting passwords, API keys or other secrets into any online tool.

Frequently Asked Questions

How do I convert XML to JSON online?

Paste your XML into the input box or upload an .xml file. The JSON appears instantly in the output box. Then copy it or download it as a .json file.

What happens to XML attributes?

With Keep attributes turned on, each attribute becomes a JSON key that starts with @. For example, id=5 becomes the key @id with the value 5. Turn the option off to leave attributes out.

How are repeated XML elements converted?

Two or more sibling elements with the same name become a JSON array. A single element becomes a plain object.

Why do I see an Invalid XML message?

The XML has a syntax problem such as a missing closing tag, an unescaped ampersand, an unquoted attribute or more than one root element. The message shows the line and column so you can find it.

Does the tool convert numbers and true or false values?

Yes, if Convert numbers and booleans is ticked. The text 12.50 becomes the number 12.5, while values with leading zeros such as 007 stay as text. Untick the option to keep every value as a string.

Can I convert a large XML file?

The tool runs in your browser, so speed depends on your device. Files of a few megabytes usually work well. For very large files, a command line tool or a script is a better choice.

Can this tool convert JSON back to XML?

No, this page only converts XML to JSON. For other formats, try the JSON to YAML converter or the CSV to XML converter on this site.

Is this XML to JSON converter free and private?

Yes. It is free with no sign-up and no limit. All processing happens in your browser, so your data is never sent to a server.