🛠 Developer Tools Runs In-Browser No Sign-up Large File Ready

XML to JSON Converter

Paste, upload, drag & drop, or import XML from a URL and get clean, valid JSON instantly — with live validation, tree & raw views, namespace and attribute controls, JSON Schema export, and batch conversion. Nothing ever leaves your browser.

🔒 No server storage ⚡ Instant conversion 📦 Large file support 🆓 Free forever

Convert XML to JSON

Paste XML, upload a file, drag & drop, or import from a URL — output updates live for smaller documents.

XML Input

Empty Paste, upload, or import XML to begin.
Characters0
Elements
Attributes
Max Depth
Output Size
Size Ratio
Conversion Time
⚙️ Conversion Settings

JSON Output

🕘 History (undo/redo & recent conversions)
    📦 Batch Conversion (multiple files → ZIP)

      Why Developers Choose ToolAdda's XML to JSON Converter

      🔒 100% private

      Parsing uses the browser's native DOMParser. Your XML, however sensitive, never leaves your device.

      🌳 Real tree view

      Collapsible, keyboard-accessible tree with lazy-loaded large arrays — not just a wall of text.

      🧭 Full namespace control

      Keep, partially clean, or fully strip XML namespace prefixes and xmlns declarations.

      🧩 Order-preserving mode

      The rare case of interleaved distinct tags is handled correctly with an explicit ordered output shape.

      🧬 JSON Schema export

      Generate and download a draft-07 JSON Schema inferred straight from your converted data.

      📦 Batch + ZIP

      Convert many XML files at once and download every JSON result in a single ZIP archive.

      ↶ Undo/redo history

      Every conversion is checkpointed — jump back to any previous input and output instantly.

      🔤 Encoding aware

      Automatically detects UTF-8, UTF-16, and other encodings from file BOMs and XML declarations.

      ♿ Fully accessible

      Semantic tabs, ARIA live regions, keyboard-navigable tree, and full color-contrast compliance.

      What Is XML, What Is JSON, and How Conversion Works

      What Is XML?

      XML (eXtensible Markup Language) is a text-based markup format designed to store and transport structured data in a way that is both human-readable and machine-parseable. Every piece of data is wrapped in a named element, elements can carry attributes, and elements can nest inside one another to represent hierarchy — for example, a <book> element might contain <title>, <author>, and <year> child elements, plus an id attribute. XML has been the backbone of enterprise data exchange for over two decades: SOAP APIs, RSS/Atom feeds, SVG images, Office document formats (.docx, .xlsx), configuration files, and countless legacy enterprise systems all use it.

      What Is JSON?

      JSON (JavaScript Object Notation) is a lightweight, text-based data format built from just two structures: objects (key-value pairs in curly braces) and arrays (ordered lists in square brackets), plus primitive types — strings, numbers, booleans, and null. Because it maps directly onto the object and array types every modern programming language already has, JSON became the default format for REST APIs, mobile app payloads, NoSQL databases, and frontend state management. It has no attributes, no namespaces, and no concept of "mixed content" — which is exactly why converting XML to JSON requires deliberate decisions about how to represent those XML-only concepts.

      XML vs JSON: Key Differences

      XML supports attributes, namespaces, comments, processing instructions, mixed content (text and elements interleaved), and schema validation via XSD or DTD. JSON supports none of these natively — it only has objects, arrays, and primitives. This is precisely the translation problem an XML to JSON converter solves: attributes must be folded into object keys (commonly with an @ prefix), repeated elements must become arrays, and namespace prefixes must be kept, cleaned, or stripped based on what the consuming application actually needs.

      Advantages of JSON

      • Smaller payload size — no closing tags, no attribute syntax overhead.
      • Native parsing in every modern language (JSON.parse in JavaScript, json.loads in Python, and so on) with zero extra libraries.
      • Simpler mental model: everything is an object, array, or primitive value.
      • The de facto standard for REST APIs, GraphQL responses, and mobile app payloads.

      Advantages of XML

      • Formal schema validation (XSD/DTD) enforces structure and types before data is even parsed.
      • Native support for namespaces, avoiding name collisions across combined vocabularies.
      • Mixed content (text interleaved with elements) suits document-like data such as rich text or SVG.
      • Long-standing enterprise tooling: XSLT transforms, XPath queries, and mature validation pipelines.

      How XML to JSON Conversion Works

      This converter walks the parsed XML document tree exactly the way a compiler walks an abstract syntax tree. For each element, it reads any attributes into object keys, recurses into child elements, and collects text content. When the same tag name repeats under one parent, those values collapse into a JSON array so no data is lost; when it doesn't repeat, it becomes a single key. Text-only elements become plain string, number, or boolean values (when Infer Numbers/Booleans is enabled), while elements with both attributes and children become nested objects. The whole process runs synchronously in your browser using the same DOMParser API that browsers use to parse XHTML and SVG — no server round-trip, no third-party API call.

      XML Structure Explained: Elements, Attributes, and Text

      An XML element is defined by a start tag and matching end tag, like <author>Frank Herbert</author>. Attributes live inside the start tag as name-value pairs, like id="1" in <book id="1">. Text content sits between the start and end tags. An element can have attributes, text, child elements, or any combination — and it's exactly this flexibility that makes a one-size-fits-all conversion impossible, which is why this tool exposes attribute, namespace, and array-handling settings instead of hard-coding one opinionated shape.

      JSON Structure Explained: Objects, Arrays, and Primitives

      A JSON object is an unordered set of key-value pairs; a JSON array is an ordered list of values; primitives are strings, numbers, booleans, and null. Critically, JSON objects in most implementations (including every modern JavaScript engine) do preserve key insertion order in practice, which is why the default compact conversion mode here is accurate for the overwhelming majority of real-world XML — the rare exception is when two different, non-repeating tags are interleaved under one parent, which is exactly the case the Preserve Order setting exists to handle correctly.

      Namespaces

      XML namespaces prevent naming collisions when combining vocabularies from different sources — for example, mixing a custom schema with SOAP envelope elements. A namespace is declared with an xmlns or xmlns:prefix attribute and referenced via a colon-separated prefix, like soap:Envelope. Since JSON has no namespace concept, this converter gives you three clear choices: keep everything as-is (safest, most literal), drop only the noisy xmlns declaration attributes while keeping prefixed names (cleanest for most APIs), or strip prefixes entirely for the simplest possible keys (fastest to consume, with a small risk of key collisions if two namespaces reuse the same local name).

      Attributes

      Because JSON objects only have keys and values, XML attributes need a convention to avoid clashing with child element names. The widely used convention — and this tool's default — is prefixing attribute keys with @, so <book id="1"> becomes {"book":{"@id":"1"}}. If your downstream code doesn't care about the distinction between attributes and elements, switch to the plain-key mode or ignore attributes altogether.

      Arrays

      Because a single XML document can't tell you in advance whether a tag "might" repeat, this converter defaults to smart detection: a tag becomes a JSON array only when it actually appears more than once under the same parent in your specific document. This keeps single-occurrence data as plain objects rather than needlessly wrapping everything in one-element arrays. If your consuming code expects a predictable, always-an-array shape regardless of how many times a tag appears, switch Array Detection to Force.

      Nested Objects

      Deeply nested XML — common in SOAP responses, RSS feeds, and enterprise configuration files — converts into equally nested JSON objects and arrays, preserving the full hierarchy. The Max Depth statistic in the validation panel tells you how deep your specific document goes, which is useful for spotting unexpectedly deep or flat structures before you write code against the output.

      API Development, REST APIs & System Integration

      Many backend systems — especially SOAP web services, older enterprise platforms, and telecom or banking APIs — still speak XML natively, while modern frontends, mobile apps, and serverless functions expect JSON. Converting at the integration boundary (an API gateway, a middleware layer, or a one-off migration script) lets both sides keep using their preferred format. This tool is ideal for prototyping that mapping quickly: paste a real XML response, tune the settings until the JSON shape matches what your code expects, then replicate that logic in your actual integration layer.

      Configuration Files, Mobile Apps & Frontend Development

      Legacy configuration formats (Java-style XML configs, Android layout/resource files, MSBuild project files) are still authored in XML but are often easier to consume programmatically as JSON — for build tooling, static site generators, or config-driven frontend components. Converting once during a build step, rather than parsing XML at runtime in the browser or a mobile app, keeps client-side code simpler and faster.

      Data Exchange & Backend Development

      Data exchange between two systems only works when both sides agree on a format, and in practice that agreement is rarely symmetric: a partner bank, a government portal, or a decades-old ERP system may only speak XML, while your backend's ORM, message queue, and cache all expect JSON natively. Backend developers typically handle this at the edge — an ingestion service, a webhook handler, or a scheduled import job — converting XML payloads to JSON as early as possible so the rest of the codebase never has to deal with attributes, namespaces, or mixed content again. Prototyping that conversion here, against a real sample payload, is usually faster than guessing at the shape and iterating inside your actual backend code.

      Common XML Errors and Validation Tips

      • Mismatched or unclosed tags — every opening tag needs an exact, case-sensitive matching closing tag.
      • Multiple root elements — a well-formed XML document must have exactly one top-level element; wrap siblings in a container tag.
      • Unescaped special characters — a bare &, <, or > inside text content breaks parsing; use &amp;, &lt;, &gt;, or wrap the content in a CDATA section.
      • Duplicate attributes — an element cannot repeat the same attribute name twice.
      • Invalid attribute quoting — attribute values must be wrapped in matching single or double quotes.

      This converter validates well-formedness before every conversion attempt and surfaces the exact error message plus a line/column reference whenever the browser's parser provides one — so you can jump straight to the problem instead of scanning the whole document by eye.

      Best Practices for XML to JSON Conversion

      1. Decide upfront how your consuming code wants attributes represented, and set Attributes accordingly rather than post-processing the output.
      2. Use Force array mode for any tag your code will iterate over, even if today's sample document only has one occurrence.
      3. Enable Remove Empty Nodes when converting sparse, optional-heavy schemas to avoid littering your JSON with empty strings and objects.
      4. Reach for Preserve Order only when you specifically need exact document order of interleaved, non-repeating tags — it produces a different (ordered-list) JSON shape than the default compact mode.
      5. Always check the validation panel and statistics before trusting a conversion on a document you haven't seen the shape of before.

      Privacy & Security

      This tool performs every step — parsing, validation, conversion, tree rendering, schema generation — entirely inside your browser's JavaScript engine using the native DOMParser API. No XML or JSON you work with is ever transmitted to ToolAdda's servers or any third party; the only exception is the optional Import from URL feature, which fetches directly from the URL you provide, from your own browser, and the URL Import feature is the only path where any network request happens at all. Because DOMParser does not resolve external entities or fetch external DTDs, this tool is also not vulnerable to XML External Entity (XXE) attacks the way some naive server-side XML parsers can be — a meaningful security advantage over pasting sensitive XML into a server-processed converter.

      Why Choose ToolAdda's XML to JSON Converter

      Most free XML to JSON tools stop at a single "convert" button and a plain textarea. This one adds a real collapsible tree view, exact namespace and attribute control, an order-preserving mode most competitors don't offer at all, JSON Schema generation, batch-to-ZIP conversion, and full undo/redo history — while remaining entirely private, free, and fast enough for large documents. It's built to be the tool you reach for whether you're debugging a single API response or migrating a whole legacy XML pipeline.

      Expert Tips

      • When migrating a SOAP API to JSON, start with Namespaces set to "keep" so nothing is silently lost, then simplify once you've confirmed which fields your new code actually needs.
      • Use the generated JSON Schema as a starting point for TypeScript interfaces or API documentation — it's far faster than hand-writing one from scratch.
      • For recurring conversion jobs (a nightly export, a batch of vendor feeds), use Batch Conversion to process every file with identical settings in one pass, then diff the ZIP output between runs to catch upstream schema drift.

      Using the Converted JSON in Your Code

      This page is a browser tool, not a hosted API — everything runs client-side, so there's no endpoint to call. If you want to replicate the same conversion in your own backend or scripts, here's the equivalent logic in a few common stacks, plus how to send the resulting JSON to a REST API.

      // Node.js — parse XML to a JS object using the built-in DOMParser
      // equivalent (e.g. the "xmldom" or "fast-xml-parser" package),
      // then send it wherever you need.
      const { XMLParser } = require("fast-xml-parser");
      
      const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "@" });
      const xml = require("fs").readFileSync("data.xml", "utf8");
      const json = parser.parse(xml);
      
      console.log(JSON.stringify(json, null, 2));
      # Python — convert XML to JSON with xmltodict
      import xmltodict, json
      
      with open("data.xml", "r", encoding="utf-8") as f:
          data = xmltodict.parse(f.read())
      
      print(json.dumps(data, indent=2))
      // Send the converted JSON to your own REST API
      const response = await fetch("https://api.example.com/import", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(convertedJson),
      });
      
      if (!response.ok) throw new Error(`Import failed: ${response.status}`);
      console.log("Imported successfully");

      Frequently Asked Questions

      What is an XML to JSON converter?

      An XML to JSON converter transforms XML markup — its elements, attributes, and text content — into an equivalent JSON structure that is easier to consume in JavaScript, REST APIs, and modern applications.

      Is this XML to JSON converter free?

      Yes. ToolAdda's XML to JSON converter is completely free, has no usage limits, and requires no account or sign-up.

      Is my XML data uploaded to a server?

      No. Parsing and conversion happen locally in your browser using the built-in DOMParser. Nothing you paste, upload, or import is ever sent to ToolAdda's servers.

      How are XML attributes represented in JSON?

      By default, attributes get an @ prefix (for example <book id="1"> becomes {"book":{"@id":"1"}}). You can switch to a plain key with no prefix, or ignore attributes entirely in Settings.

      Do repeated XML tags become a JSON array?

      Yes, by default. When the same tag appears more than once under the same parent, the converter groups those elements into a JSON array so no data is lost. You can also force every element into an array for consistency.

      How does the converter handle XML namespaces?

      You can keep namespace prefixes and xmlns declarations as-is, drop only the xmlns declaration attributes while keeping prefixed names, or strip all namespace prefixes from element and attribute names.

      What does Preserve Order mode do?

      The default compact JSON shape groups repeated tags into arrays, which can lose the exact original sequence when different tags are interleaved. Preserve Order mode outputs an ordered list of child elements instead, guaranteeing the exact original document order.

      Can I remove empty XML nodes from the JSON output?

      Yes. Enable Remove Empty Nodes in Settings to recursively strip empty strings, empty objects, and empty arrays from the converted JSON.

      Can I skip the root element wrapper in the output?

      Yes. Enable Unwrap Root to return the root element's contents directly instead of nesting everything under a top-level key named after the root tag.

      Does the converter validate XML before converting?

      Yes. Every conversion attempt runs the XML through well-formedness validation first. If the XML is invalid, the validation panel shows the error message along with the line and column number where possible.

      Can I upload a large XML file?

      Yes. Large files are read via streaming file APIs and conversion is deferred a frame so the UI stays responsive, with a visible progress indicator. Extremely large files (tens of megabytes) may take a few seconds since parsing happens in your browser, not on a server.

      Does this tool detect file encoding automatically?

      Yes. When you upload a file, the converter inspects the byte-order mark (BOM) and the XML declaration's encoding attribute to correctly decode UTF-8, UTF-16, and other common encodings before conversion.

      Can I import XML directly from a URL?

      Yes. Paste a public URL into the Import from URL field. The request is made directly from your browser, so the target server must allow cross-origin (CORS) requests for the fetch to succeed.

      Can I generate a JSON Schema from my XML?

      Yes. After converting, click Export JSON Schema to download a draft-07 JSON Schema inferred from the structure and types of your converted data.

      Can I convert multiple XML files at once?

      Yes. Use the batch conversion panel to select multiple .xml files; each is converted with your current settings and you can download all the resulting JSON files together as a single ZIP archive.

      Does the tool have undo and redo?

      Yes. Every successful conversion is saved to a short history. Use Undo and Redo, or click any entry in the History panel, to jump back to a previous XML input and its converted output instantly.

      Does the converter support CDATA sections and comments?

      CDATA sections are treated like regular text content and merged into the surrounding element's value. XML comments and processing instructions are ignored, since they carry no data relevant to the JSON structure.

      Is this safe from XML external entity (XXE) attacks?

      Yes. Conversion uses the browser's native DOMParser, which does not resolve external entities or fetch external DTDs, so it is not vulnerable to XXE-style attacks the way some naive server-side XML parsers can be.

      Can I switch between pretty-printed and minified JSON?

      Yes. Toggle Minify in Settings, or use the separate Download Pretty JSON and Download Minified JSON buttons to get either format regardless of the current toggle.

      What indentation options are available?

      You can choose 2 spaces, 4 spaces, or tab characters for indentation when pretty-printing the JSON output.

      Can I convert the JSON back to XML?

      Yes — use ToolAdda's separate JSON to XML Converter to reverse the process.

      Does this work on mobile devices?

      Yes. The editor, tree view, and all controls are fully responsive and touch-friendly, and every feature works the same on mobile browsers as on desktop.

      Ready to Convert Your XML?

      Paste, upload, or import your XML and get clean, structured JSON in seconds — free, private, and built for real developer workflows.

      ⚡ Convert XML to JSON Now
      XML → JSON