ToolJutsu
All tools
Developer Tools

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.

0 chars
Tip: press Ctrl/ + Enter
Processed on your device. We never see your files.

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

  1. Paste your XML into the input box, or drop an .xml file onto it.
  2. Click Convert to JSON, or press Ctrl/Cmd + Enter.
  3. Read the pretty-printed JSON in the output box.
  4. Copy it with one click to use elsewhere.
  5. 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?
No. Parsing is done by your browser's built-in DOMParser and the conversion runs locally in JavaScript. Nothing you paste or drop leaves your device, which you can verify in the browser's Network tab.
How are XML attributes represented in the JSON?
Each attribute becomes a key on its element's object, prefixed with an @ symbol. For example produces a key "@id": "1". This keeps attributes distinct from child elements, which use plain key names.
What is the #text key for?
When an element has both attributes (or child elements) and text content, the text is stored under a #text key. When an element has only text and no attributes, the text becomes the element's direct value instead, with no #text wrapper.
How are repeated XML elements handled?
If an element contains several child elements with the same tag name, they are collected into a JSON array. A tag that appears only once becomes a single object rather than a one-element array.
What happens if my XML is malformed?
The browser's parser reports malformed XML by inserting a parsererror element into the document. The tool detects this and shows a clear error message instead of producing broken output.

Related tools