Micru Logo

XML to JSON

Convert XML documents to JSON format. Attributes are prefixed with @, text content is preserved, and repeated elements are collected into arrays.

All processing is done locally in your browser. No data is sent to our servers.

Why Convert XML to JSON?

JSON has become the dominant data interchange format for web APIs, while XML remains ubiquitous in enterprise systems, SOAP services, configuration files, and legacy integrations. Converting XML to JSON bridges these two worlds: it lets modern JavaScript/TypeScript code work with XML data without loading a full XML parser, and makes the data compatible with JSON-native tooling like jq, MongoDB, and most REST APIs.

JSON is also typically more compact than equivalent XML (no closing tags or quotes around attribute names), easier to read for developers unfamiliar with XML, and natively supported in every modern programming language without additional libraries.

Conversion Conventions

XML and JSON have fundamentally different data models, so any conversion requires a set of mapping conventions. This tool uses the following rules:

  • Elements become JSON object keys. The root element wraps the entire output object.
  • Attributes are prefixed with @ (e.g. lang="en" becomes "@lang": "en") to distinguish them from child elements.
  • Text-only elements without attributes become a plain string value (not a nested object).
  • Repeated sibling elements with the same tag name are automatically collected into a JSON array.
  • Mixed-content elements (both text and child elements) store the text under a #text key alongside the child element keys.

Common Use Cases

SOAP to REST Migration

When modernising a SOAP-based integration to a REST API, converting the XML response schema to JSON helps plan the new response shape and write transformers for backward compatibility layers.

RSS/Atom Feed Processing

Feed aggregators often need to normalise RSS (XML) and JSON Feed formats into a single structure. Converting the RSS XML to JSON first simplifies building a unified parser.

Data Exploration

JSON is far easier to explore with browser DevTools or jq. Converting an unfamiliar XML document to JSON lets you query its structure quickly before writing a full parser.

MongoDB & Document Stores

Importing XML-sourced data into a document database requires a JSON representation. Converting the XML to JSON gives you a structure you can import directly with mongoimport or similar tools.

Limitations of XML-to-JSON Conversion

XML and JSON have different expressive power. XML supports mixed content (text interleaved with child elements), namespace declarations, processing instructions, and DTD references - none of which have a direct JSON equivalent. This converter focuses on the common case of data-oriented XML (no mixed content, no namespaces). For namespace-aware XML or schema-driven conversions, a purpose-built XSLT or library-based conversion is more appropriate.