XML to JSON
Convert XML documents into JSON.
Attributes become keys prefixed with @; an element's text content becomes a #text key, or the value directly when an element holds only text. Repeated sibling elements of the same name are grouped into an array.
How to use XML to JSON
What this tool does
This tool converts XML into JSON. It parses your XML with the browser’s native
DOMParser, then walks the resulting document tree and builds an equivalent
JSON structure: elements become objects, attributes become @-prefixed keys,
and text content becomes either a #text key or the element’s direct value.
The output is pretty-printed JSON, ready to use. Everything runs inside your
browser, so the XML you paste is never sent anywhere.
Why you might need it
XML is still the format behind RSS and Atom feeds, SOAP services, sitemaps, SVG, Office documents, and countless enterprise systems. Modern JavaScript, though, is far happier working with JSON: you can index into it, map over it, and pass it straight to most APIs. Converting XML to JSON lets you pull data out of an older format and into a shape your code can use directly, without dragging in a heavyweight XML library.
How to use it
- Paste your XML into the input box, or drop an
.xmlfile onto it. - Click Convert to JSON, or press Ctrl/Cmd + Enter.
- Read the pretty-printed JSON in the output box.
- Copy it with one click to use elsewhere.
- If the XML is malformed, a clear error tells you the parse failed — fix the XML and convert again.
The conversion conventions
Because XML and JSON model data differently, the tool follows a fixed set of
rules so the output is predictable. An element becomes a JSON object.
An attribute becomes a key on that object prefixed with @, so
<book id="1"> yields "@id": "1". Text content is handled two ways: if an
element contains only text and has no attributes, that text becomes the
element’s value directly (<title>Hello</title> becomes "title": "Hello");
if the element also has attributes or children, the text is placed under a
#text key so nothing collides. Repeated sibling elements with the same tag
name are grouped into an array, while a tag that appears once stays a plain
object.
Common pitfalls
The single-versus-array rule is the most common surprise. An element that
happens to appear once becomes an object, but the same element appearing twice
becomes an array — so code consuming the JSON should be ready for both, or you
should normalise after conversion. Attribute values always come through as
strings, even when they look like numbers or booleans, because XML itself has no
types. Comments, processing instructions, and namespace prefixes are not given
special treatment — namespaced tag names keep their prefix as written. And if
the parser reports an error, check for unclosed tags, mismatched tag names, or
stray < and & characters that should have been escaped.
Tips and advanced use
For an RSS or Atom feed, converting to JSON gives you a clean array of items you
can iterate over directly. When you need a specific value, remember the path
includes the @ prefix for attributes and may include #text for mixed
content. If you control both ends of a conversion, pairing this with a JSON to
XML tool lets you round-trip data between the two formats. And because the whole
process runs client-side, you can convert XML containing internal endpoints,
identifiers, or other sensitive details without any of it being uploaded.
Frequently asked questions
Is my XML uploaded to a server?
How are XML attributes represented in the JSON?
What is the #text key for?
How are repeated XML elements handled?
What happens if my XML is malformed?
Related tools
XML Formatter
Pretty-print and indent messy XML.
YAML to JSON
Convert YAML into JSON.
JSON to YAML
Convert JSON into readable YAML.
Base64 Encoder & Decoder
Encode and decode Base64, with full UTF-8 support.
URL Encoder & Decoder
Encode and decode URL-safe text.
HTML Encoder & Decoder
Encode and decode HTML entities.