Skip to content

XML to JSON

Convert XML to JSON format online instantly. Free XML to JSON converter with proper structure mapping and clean formatted output.

JSON to XML
JSON output will appear here...

About XML to JSON Conversion

Convert XML data to JSON format. Attributes are prefixed with "@", text content is stored in "#text" when mixed with elements. Repeated elements are converted to arrays.

How to Use XML to JSON

1

Paste your XML

Paste XML (full document with <?xml?> declaration or just a fragment) into the input editor. SOAP envelopes, RSS feeds, configs, and partial elements all work.

2

Configure conversion

Choose how to handle attributes (prefix with '@' or place in '@attributes' subobject), text content (as direct value or '#text'), and namespaces (preserve prefixes or strip).

3

View JSON output

Element names become JSON keys; nested elements become nested objects; repeated elements become arrays. CDATA sections are preserved as raw string values.

4

Copy or download

Click Copy to put the JSON on your clipboard, or Download as a .json file. Use it in modern APIs, JavaScript apps, NoSQL databases, or anywhere JSON is preferred over XML.

When to Use XML to JSON

Modernizing legacy SOAP service consumption

SOAP services return XML, but modern client code prefers JSON. Convert SOAP responses to JSON for use in JavaScript apps, REST APIs that wrap SOAP backends, or microservice translators between protocols. Reduces XML parsing complexity in your application code.

Processing RSS and Atom feeds

RSS and Atom feeds (blog posts, news, podcasts) are XML. Converting to JSON simplifies feed aggregation, content extraction, and custom display. Especially useful when building feed readers, news aggregators, or content pipelines that combine multiple sources.

Migrating XML configs to JSON ecosystems

Older Java applications often use XML configs (Spring beans, Tomcat web.xml). Converting to JSON enables migration to modern config systems (Spring Boot's application.json, microservice configs) or just makes the config easier for JS-based tooling to process.

Extracting data from EPUB, DOCX, SVG, KML files

Many file formats are XML internally. EPUB books, DOCX documents, SVG images, KML map files all use XML. Extract specific data programmatically by converting XML to JSON, then using familiar JSON manipulation patterns instead of XPath.

XML to JSON Examples

Simple XML element

Input
<book id="1"><title>Hamlet</title><author>Shakespeare</author></book>
Output
{
  "book": {
    "@id": "1",
    "title": "Hamlet",
    "author": "Shakespeare"
  }
}

The book element becomes a JSON object. The id attribute is prefixed with @ (a common convention). Child elements (title, author) become nested keys with their text content as values. Note: exact attribute notation varies by converter — check the specific tool's documentation.

Repeated elements become arrays

Input
<library><book>X</book><book>Y</book><book>Z</book></library>
Output
{"library":{"book":["X","Y","Z"]}}

When the same element appears multiple times under a parent, it becomes a JSON array. Single occurrences stay as values; multiple occurrences trigger array creation. This is the standard behavior for XML→JSON conversion in libraries like fast-xml-parser.

Mixed content with attributes

Input
<message lang="en">Hello <b>World</b>!</message>
Output
{
  "message": {
    "@lang": "en",
    "#text": "Hello World!",
    "b": "World"
  }
}

Mixed content (text plus child elements) is the trickiest case. Different converters handle this differently — some flatten the text, some preserve order. This example shows one common approach; verify your converter's specific behavior for mixed content.

Tips & Best Practices for XML to JSON

  • 1.Check the converter's attribute notation. Some use '@attr', others use '@attributes' subobject, others prefix with '_'. Different libraries (xml2js, fast-xml-parser, xml-js) have different defaults — use consistent settings across your project.
  • 2.For SOAP envelopes specifically, prefer libraries that handle namespaces well (xml2js with explicitNamespaces option, or fast-xml-parser with namespace processors). Manually mapping SOAP namespaces to JSON gets messy quickly.
  • 3.Round-trip JSON → XML → JSON is rarely identical without specific configuration on both sides. XML's mixed content, attribute vs element distinction, and namespace handling don't all map cleanly to JSON. For critical round-trips, pick a library that supports it (like fast-xml-parser).
  • 4.Validate XML before converting. Malformed XML produces unhelpful errors during conversion; pre-validation with a strict XML parser catches issues early. xmllint (command line) or online XML validators work well.
  • 5.For large XML files (>50 MB), use streaming converters like 'sax-stream' or 'expat-style' parsers that don't load the entire DOM. The browser-based converter here uses DOM parsing which has memory limits proportional to file size.
  • 6.After conversion, validate the JSON output too. Unexpected XML structures (nested mixed content, processing instructions, namespace prefixes in unexpected places) can produce JSON that's syntactically valid but structurally weird — validate against your expected schema.

Frequently Asked Questions

Modern APIs and JavaScript applications use JSON, but legacy systems, SOAP services, RSS feeds, and many enterprise tools still output XML. Converting bridges old and new — process XML data with modern JSON-based tools, frameworks, and cloud services without having to learn XML parsing.