Skip to content
← Blog
🔒 All in your browser 🚫 No uploads stored
Guide

XML to JSON Conversion: Complete Guide with Examples

Bill Crawford — Guide — February 2026 — 8 min read  ·  Last updated February 22, 2026

The XML to JSON Converter transforms XML documents into JSON format instantly in your browser. Whether you're migrating a legacy system that produces XML to a modern API that consumes JSON, or just need to read XML data more easily, this tool handles the conversion without any server upload.

Connect on LinkedIn →

Contents
  1. XML vs JSON: key differences
  2. How to use the tool
  3. How XML maps to JSON
  4. Worked examples
  5. Handling XML attributes
  6. Tips and edge cases

Ready to convert? Paste your XML and get JSON instantly.

Open XML to JSON ↗

XML vs JSON: Key Differences

Both XML and JSON are text-based formats for representing structured data, but they have very different designs. XML was created in 1998 for document markup and uses angle-bracket tags, attributes, and nesting. JSON emerged from JavaScript in the early 2000s and represents data as key-value pairs, arrays, and nested objects.

JSON has become the dominant format for APIs and web services because it's more compact, easier to read, and maps directly to data structures in most programming languages. XML still dominates in enterprise systems, configuration files (Maven, Spring, Android), document formats (DOCX, SVG), and SOAP web services.

FeatureXMLJSON
SyntaxTags: <name>value</name>Key-value: {"name":"value"}
VerbosityHigh — repeated tag namesCompact
AttributesYes — metadata on elementsNo — all data is values
ArraysRepeated sibling elementsNative array syntax []
CommentsYes — <!-- comment -->No

How to Use the Tool

1
Paste your XML

Paste well-formed XML into the input panel. The XML must have a single root element. The converter handles nested elements, attributes, text content, CDATA sections, and repeated sibling elements (which become JSON arrays).

2
Click Convert

The tool parses the XML and outputs equivalent JSON. Conversion happens client-side — your data never leaves your browser.

3
Copy or download the JSON

Use the Copy button to copy to clipboard, or download the result as a .json file.

How XML Maps to JSON

Element with text content

<name>Alice</name>  →  "name": "Alice"

Nested elements

<person>
  <name>Alice</name>
  <age>30</age>
</person>
→
{"person": {"name": "Alice", "age": "30"}}

Repeated elements become arrays

<items>
  <item>Apple</item>
  <item>Banana</item>
</items>
→
{"items": {"item": ["Apple", "Banana"]}}

Attributes

XML attributes are typically mapped to JSON keys prefixed with @ or _, depending on the conversion library. Our tool maps them to @attribute_name keys alongside the element's text content.

<price currency="USD">9.99</price>
→
{"price": {"@currency": "USD", "#text": "9.99"}}

Worked Examples

Example 1 — Product catalog entry

<product id="P001">
  <name>Wireless Headphones</name>
  <price currency="USD">79.99</price>
  <tags>
    <tag>audio</tag>
    <tag>wireless</tag>
  </tags>
</product>
{
  "product": {
    "@id": "P001",
    "name": "Wireless Headphones",
    "price": { "@currency": "USD", "#text": "79.99" },
    "tags": { "tag": ["audio", "wireless"] }
  }
}

Handling XML Attributes

Attributes are the trickiest part of XML-to-JSON conversion because JSON has no direct equivalent. Common conventions include prefixing attribute keys with @, storing them in a separate _attributes object, or flattening them directly into the parent object. Check which convention your target system expects before converting.

Watch out for: XML namespaces (xmlns: declarations) — these often survive conversion as attribute keys and may need to be stripped if your JSON consumer doesn't expect them.

Tips and Edge Cases

Frequently Asked Questions

Does the tool handle malformed XML?
The tool requires well-formed XML — every tag must be closed, attributes must be quoted, and the document must have a single root element. If your XML is malformed, the converter will show an error. Use an XML validator first if you're unsure.
Are XML namespaces preserved?
Yes — namespace declarations and prefixes are preserved as attribute keys in the JSON output. If you don't need them, strip them manually from the JSON or use a namespace-stripping option if available.
What about XML with mixed content?
Mixed content — elements that contain both text and child elements — is complex to represent in JSON. The text portions are stored under a '#text' key alongside the child element keys.
Can I convert back from JSON to XML?
Not with this tool directly. The conversion is lossy in some cases — attribute metadata, processing instructions, and comments don't survive to JSON. Use the JSON to XML tool if you need to go the other direction.

Related Tools

Further reading: MDN — Working with JSON · JSON.org Specification

BC
Bill Crawford
Founder, Data Conversion Center

Bill Crawford is a data systems developer and technical founder with over 30 years of professional experience in accounting, finance, and business operations.

He holds a Bachelor's degree in Accounting and has spent more than three decades working within financial and operational environments. Over the past 10 years, he has been heavily involved in the development, implementation, and refinement of financial and enterprise data systems for both Fortune 500 companies and smaller organizations.

His work bridges finance and technology — combining deep domain knowledge in structured reporting and accounting workflows with hands-on SQL development and database architecture experience.

Bill founded DataConversionCenter.com to build practical, browser-based tools that simplify complex data challenges, including:

Rather than focusing on theoretical examples, his tools and articles are informed by real-world challenges encountered in enterprise reporting systems, financial databases, and operational data environments.

Professional Background

Bill's mission is to reduce friction in data workflows — particularly for professionals working with structured financial, operational, and reporting data.