XML to JSON Converter

Convert XML to JSON format online. Handles attributes, nested elements, and repeated tags. Free XML to JSON converter.

What is XML to JSON Converter?

An XML to JSON converter takes an XML document and produces the equivalent JSON structure. XML dominated data interchange from the late 1990s onwards and remains entrenched wherever long-lived systems live: SOAP web services, RSS and Atom feeds, sitemaps, Android layouts, Maven and Ant build files, Office document formats and most government and banking data exchange. JSON is what modern web and mobile clients expect. Converting between them is one of the most common integration tasks in software, and it is not a purely mechanical translation — XML carries concepts that JSON has no way to express, so any conversion involves deliberate trade-offs about attributes, repeated elements and namespaces.

How It Works

The tool parses your XML into a document tree, then walks that tree emitting JSON. Element names become object keys and nested elements become nested objects. Because JSON has no notion of attributes, they are conventionally prefixed with an @ symbol so they cannot collide with a child element of the same name, and where an element has both attributes and text, the text is placed under a dedicated key. Sibling elements sharing a name are collected into an array. CDATA sections are unwrapped into plain text values, character entities such as < are decoded, and comments and processing instructions are discarded because JSON cannot represent them. Parsing happens entirely in your browser, so the document never leaves your device.

Examples

Elements and attributes → keys, with @ marking attributes
Input
<book id="42" lang="en">
  <title>Dune</title>
  <year>1965</year>
</book>
Output
{
  "book": {
    "@id": "42",
    "@lang": "en",
    "title": "Dune",
    "year": "1965"
  }
}
Repeated sibling elements → array
Input
<tags>
  <tag>sci-fi</tag>
  <tag>classic</tag>
</tags>
Output
{
  "tags": {
    "tag": ["sci-fi", "classic"]
  }
}

Common Use Cases

  • •Converting SOAP or legacy XML API responses into JSON for a JavaScript or mobile front end
  • •Turning RSS and Atom feeds into JSON for use in a custom reader or dashboard
  • •Migrating XML configuration files to JSON as part of modernising a build or deployment pipeline
  • •Loading XML data exports into document databases such as MongoDB that store JSON natively
  • •Inspecting deeply nested XML in a more readable form while debugging an integration
  • •Preparing XML-sourced fixtures as JSON for test suites and API mocking tools

Frequently Asked Questions

How are XML attributes handled?▼

Attributes are prefixed with @ in the JSON output (e.g., @id, @class).

Why does the JSON output look different from the XML structure?▼

The two formats do not map cleanly onto each other. XML distinguishes attributes from child elements, allows repeated sibling elements with the same name, and carries namespaces and comments; JSON has none of those concepts. Converters therefore adopt conventions — commonly prefixing attributes with `@` and putting element text under a key such as `#text`.

How are repeated XML elements handled?▼

They become a JSON array. The catch is that a list with a single item is ambiguous: `<items><item>a</item></items>` can convert to either a string or a one-element array. This is a frequent source of bugs when code assumes an array and receives a bare value, so validate against the case of exactly one child.

What happens to XML attributes?▼

They are kept as ordinary keys, conventionally marked with an `@` prefix so they cannot collide with a child element of the same name. An element that has both attributes and text content becomes an object holding the attribute keys plus a text key rather than a plain string.

Are namespaces preserved?▼

Prefixes are normally retained as part of the key name, so `<ns:title>` becomes the key `ns:title`. The namespace URI declared by `xmlns` is not something JSON can express structurally. If your consumer relies on namespace resolution, keep the XML.

Will comments, CDATA and processing instructions survive?▼

Comments and processing instructions are dropped, because JSON has no equivalent. CDATA sections are unwrapped and their contents become the element's text value, correctly unescaped.

Why does XML sometimes convert to much larger JSON?▼

Because attribute and text markers add keys that the XML expressed structurally. Deeply nested documents with many attributes can grow rather than shrink. If size matters, run the result through the JSON Minifier and compare.

Related Tools

More from Converters: