← All Posts

How to Convert XML to JSON Online (Free)

Published on February 7, 2026

XML vs JSON: Two Data Formats Compared

XML (eXtensible Markup Language) and JSON (JavaScript Object Notation) are both used to represent structured data, but they take fundamentally different approaches. XML uses a tag-based syntax with opening and closing elements, attributes, namespaces, and processing instructions. JSON uses a lightweight key-value pair syntax with objects, arrays, strings, numbers, booleans, and null values.

XML was the dominant data interchange format throughout the early 2000s and is still widely used in enterprise systems, SOAP web services, configuration files (like Maven's pom.xml), and document formats (like SVG and XHTML). JSON, on the other hand, has become the standard for REST APIs, modern web applications, and configuration files. Converting between these two formats is a common task when integrating legacy systems with modern applications.

Why XML to JSON Conversion Is Challenging

Unlike CSV to JSON conversion, which maps neatly from rows and columns to arrays and objects, XML to JSON conversion has inherent ambiguities. XML has features that JSON simply does not support natively, which means the converter must make decisions about how to represent certain XML constructs in JSON.

Attributes vs Elements

XML elements can have both attributes and child elements. JSON objects only have keys and values. A common convention is to prefix attribute names with @ to distinguish them from child elements:

<!-- XML -->
<book id="123" lang="en">
  <title>Clean Code</title>
  <author>Robert C. Martin</author>
</book>

// JSON output
{
  "book": {
    "@id": "123",
    "@lang": "en",
    "title": "Clean Code",
    "author": "Robert C. Martin"
  }
}

Text Nodes and Mixed Content

When an XML element contains both text and child elements (mixed content), the text must be preserved somehow. Most converters use a special key like #text to hold the text content:

<!-- XML with mixed content -->
<note>
  This is <b>important</b> text.
</note>

// JSON output
{
  "note": {
    "#text": "This is  text.",
    "b": "important"
  }
}

Repeated Elements and Arrays

In XML, you can have multiple sibling elements with the same tag name. In JSON, duplicate keys in an object are not allowed, so repeated elements must be converted into an array:

<!-- XML with repeated elements -->
<library>
  <book>Clean Code</book>
  <book>The Pragmatic Programmer</book>
  <book>Refactoring</book>
</library>

// JSON output
{
  "library": {
    "book": [
      "Clean Code",
      "The Pragmatic Programmer",
      "Refactoring"
    ]
  }
}

How to Use the PulpMiner XML to JSON Tool

Using PulpMiner's XML to JSON converter is straightforward. Paste your XML content into the input editor on the left side. The tool will automatically parse the XML and display the equivalent JSON on the right. If your XML has syntax errors, the tool will highlight them so you can fix them before conversion.

The converter handles attributes (prefixed with @), text nodes (using #text), CDATA sections, and deeply nested structures. You can copy the resulting JSON to your clipboard or download it as a file. The tool works entirely in your browser, so no data is sent to any server.

Integrating XML to JSON Conversion in Your API Workflow

Many enterprise APIs still return XML responses, especially SOAP services and older REST APIs. If your application consumes JSON, you need a conversion layer. Here is a basic example of converting XML to JSON in a Node.js environment using the popular xml2js library:

const xml2js = require("xml2js");

const xml = `
<response>
  <status>200</status>
  <data>
    <user id="1">
      <name>Alice</name>
      <email>alice@example.com</email>
    </user>
  </data>
</response>`;

xml2js.parseString(xml, { explicitArray: false }, (err, result) => {
  if (err) throw err;
  console.log(JSON.stringify(result, null, 2));
});

For quick, one-off conversions during development or debugging, PulpMiner's online tool is faster than writing code. You can paste an API response directly into the tool and instantly see the JSON equivalent.

Common Pitfalls to Avoid

When converting XML to JSON, watch out for these common issues. First, namespaces can pollute your JSON keys with prefixes like soap:Envelope or xmlns:xsi. Most converters strip or preserve these depending on configuration. Second, the order of elements in XML is significant, but JSON object keys have no guaranteed order. If your application depends on element order, use arrays instead. Third, XML has no concept of data types — everything is a string. You may need to post-process the JSON to convert numeric strings to numbers and boolean strings to booleans.

When to Use XML vs JSON

Despite JSON's popularity, XML remains the better choice in certain scenarios. XML supports schemas (XSD) for strict validation, namespaces for avoiding naming conflicts, and XSLT for transformations. Document-centric applications like publishing, legal documents, and medical records often use XML because of its rich metadata capabilities. For data interchange between web services, configuration files, and modern applications, JSON is almost always the better choice due to its simplicity and native JavaScript support.

Need to extract data from websites?

PulpMiner turns any webpage into structured JSON data. No scraping code needed — just point, click, and get clean data.

Try PulpMiner Free

No credit card required