🔒 100% private — runs in your browser, nothing is uploaded

XML to JSON Converter

Convert XML to JSON and JSON back to XML — a real parser, both directions, in your browser.

XML and JSON carry the same trees in different syntax: RSS feeds, SOAP services, SVG files, Office documents and older config formats speak XML, while most modern APIs and JavaScript code speak JSON. Moving between them sounds mechanical, but the details are where converters earn their keep — attributes have no JSON equivalent, repeated elements need to become arrays, and a lone text node has to land somewhere sensible.

How the shapes map: attributes live under "@attributes", an element's text sits under "#text" when the element also has children or attributes (otherwise the element is just its text string), and repeated sibling tags become an array. Numbers stay strings — XML has no number type, and this tool will not guess one into existence.

Quick answers

How does this converter turn XML attributes into JSON?

Attributes are grouped into an object under the key "@attributes" on their element, separate from child elements and text.

For example, <a href="x">hi</a> becomes {"a": {"@attributes": {"href": "x"}, "#text": "hi"}}. Converting that JSON back to XML restores the attribute and the text, so the mapping is reversible.

Why do repeated XML tags become arrays but single tags do not?

Because that is the shape the document actually has: two <item> siblings are a list, one <item> is a single value. The converter keeps that distinction instead of wrapping everything in arrays.

It does mean the JSON shape can change if a feed that usually sends two items sends one. Code consuming converted XML should normalise single values into arrays when it needs a guaranteed list.

Does the converter turn XML numbers into JSON numbers?

No. Every text value stays a string, because XML itself has no number type — "42", "007" and "3.0" are all just text until a schema says otherwise.

Guessing would corrupt leading-zero IDs, version strings and long numbers that exceed safe integer range. If you need typed values, convert the strings in your own code where you know which fields are numeric.

How to use

  1. Pick the direction: XML → JSON or JSON → XML.
  2. Paste your document into the box — conversion happens as you type.
  3. For JSON → XML, set the root element name if the default "root" does not fit your document.
  4. Copy the output, download it as a file, or press “Use output as input” to convert straight back and check the round trip.

About this tool

This page states its mapping up front instead of hiding it. Attributes are collected under an "@attributes" object. An element that contains only text becomes that text as a plain string; when an element has children or attributes as well, its text is kept under "#text". Repeated sibling tags become an array in document order, while a tag that appears once stays a single value. CDATA sections are read as text, comments are skipped, and entity references (&amp;, &lt;, numeric ones) are decoded. Going the other way, "@attributes" and "#text" are honoured in reverse, arrays become repeated elements, and every text and attribute value is escaped, under an <?xml version="1.0" encoding="UTF-8"?> declaration.

Two honest limits. XML numbers are just text, so a value like 42 stays the string "42" in JSON — this tool will not guess types and risk turning an ID like 007 into 7. And mixed content (text interleaved between child elements, as in HTML paragraphs) is gathered into a single "#text" string rather than kept in position, because JSON has no natural way to express the interleaving. Malformed XML is reported with the problem and roughly where it happened, never silently half-converted. Nothing you paste is uploaded or stored.

Frequently asked questions

Is my XML or JSON uploaded?

No. The parser is written in JavaScript and runs in this page, on your device. Nothing you paste is sent anywhere or saved.

What happens to comments and the <?xml?> declaration?

Both are read and skipped on the way to JSON — JSON has nowhere to put them. Converting back to XML always writes a fresh UTF-8 declaration at the top.

Can it handle namespaces like <w:p> or <soap:Body>?

Yes. Colons are treated as ordinary parts of the element name, so namespaced tags convert with their full names as JSON keys. The prefixes are not resolved against namespace declarations — the name you see is the name you get.

Why did I get a "mismatched tags" error?

XML requires every opened element to close with the same name: <a><b></a> is invalid because </b> was expected first. The error names both tags so you can find the spot; unclosed elements and unterminated comments or CDATA are reported the same way.

What does CDATA do here?

A <![CDATA[ ... ]]> section is taken literally as the element’s text, markup characters and all — the standard way XML embeds text that looks like tags. On the way back to XML the text is escaped normally rather than re-wrapped in CDATA.

📦 Embed this tool on your site

<iframe src="https://verystep.com/embed/xml-json-converter/" title="XML to JSON Converter" width="100%" height="520" loading="lazy" style="border:0"></iframe>

Free to use. The embed shows a small "Powered by Verystep" link.

First time embedding? Read the step-by-step guide →

More free tools