RevealTheme logo

XML to JSON Converter

Paste an XML document and get a JSON representation in your browser. Attributes become @-prefixed keys, element text is wrapped in a #text key, and repeated sibling tags collapse into arrays.

How to use this tool

  1. 1

    Paste or type your XML into the input box.

  2. 2

    Read the converted JSON in the output panel below, which updates as you type.

  3. 3

    If the XML is malformed, fix the error shown in red and the output will reappear.

  4. 4

    Select the JSON from the output panel to copy it into your project.

How does this XML to JSON converter map elements, attributes, and text?

XML and JSON describe data differently, so any conversion has to pick conventions. This tool parses your input with the browser's built-in DOMParser in text/xml mode, then walks the resulting DOM tree with a recursive function. The document's root element name becomes the single top-level key. Each child element becomes a nested key under its parent, attributes are stored as keys prefixed with @ (so id='5' becomes '@id': '5'), and an element's text content is placed under a '#text' key rather than becoming the value directly — even a simple leaf like <name>John</name> produces {'name': {'#text': 'John'}}. When a parent has several child elements with the same tag name, those siblings are merged into a JSON array so none are lost. An element with no attributes and no text becomes null. The mapping is deliberately lossy: namespaces survive only as literal prefixed key names (ns:tag) and are never resolved, comments, processing instructions, and CDATA sections are dropped to null, the original order of mixed text-and-element content is not preserved, and nothing is type-coerced, so numbers and booleans stay as strings like '42' and 'true'.

Common use cases

  • Inspect a SOAP or legacy XML API response as JSON before wiring it into a JavaScript front end.

  • Convert an RSS or Atom feed snippet into JSON to prototype a parser quickly.

  • Turn a config file or build manifest written in XML into JSON to eyeball its structure.

  • Pull values out of an XML sitemap or data export when a JSON shape is easier to traverse.

  • Teach or learn how attributes, repeated tags, and text nodes map between the two formats.

  • Sanity-check that a small XML payload is well-formed, since malformed input shows a parser error.

Frequently asked questions

Is my XML uploaded to a server?
No. Parsing and conversion run entirely in your browser using the native DOMParser API, so nothing you paste leaves your machine.
Why is text wrapped in a #text key instead of being the value?
This converter always represents an element's character data under a '#text' key so that text can coexist with attributes and child elements. That means <name>John</name> becomes {'name': {'#text': 'John'}}, not {'name': 'John'}. If you need the scalar-shortcut form, post-process the output or use a library like fast-xml-parser.
What does the @ prefix mean?
Attributes are stored as keys prefixed with @, such as '@id', to keep them distinct from child elements that might share the same name.
How are repeated tags handled?
When a parent contains multiple child elements with the same tag name, they are collected into a JSON array under that name. A single occurrence stays a plain object, so the shape can differ depending on how many siblings exist.
Are numbers and booleans converted to real JSON types?
No. There is no type coercion, so a value like 42 or true comes through as the string '42' or 'true'. Cast values yourself after conversion if you need real numbers or booleans.
What happens to CDATA, comments, and namespaces?
CDATA sections, comments, and processing instructions are dropped and their nodes become null, so their content is lost. Namespace prefixes are kept verbatim as part of key names (ns:tag) and are never resolved. For lossless round-tripping, reach for a dedicated XML library.
Why do I see a red error message?
The tool checks the parsed document for a parsererror element. If your XML is not well-formed, the browser's parser message is shown in red and no JSON is produced until you fix it.

Related tools