BYTETOOLS

How to Convert XML to JSON Online (Step by Step)

To convert XML to JSON online, paste your XML into the ByteTools XML to JSON Converter and click Convert — it parses the document with your browser's built-in DOMParser and returns clean, pretty-printed JSON in one step. No upload, no sign-up, and nothing leaves your device, so even configuration files and API responses stay private.

XML and JSON describe the same kind of nested data, but JSON is far easier to work with in modern JavaScript and most APIs. This guide walks through the conversion and, just as importantly, shows how each part of your XML lands in the JSON so the output never surprises you.

What the converter produces

The tool follows a consistent, predictable mapping. Elements become nested objects. When the same tag repeats, those repeats collapse into an array. Attributes are preserved with an @ prefix so they never collide with child elements, and loose text inside an element that also has attributes or children is kept under a #text key. Nothing is silently dropped — every piece of the source document has a home in the result.

Step-by-step conversion

  1. Add your XML. Paste it into the input box or drop a .xml file onto the page.
  2. Click Convert to JSON. The DOMParser reads the document and builds the JSON structure instantly.
  3. Read the pretty-printed output. Indentation makes the nesting obvious; attributes appear under @ keys.
  4. Fix any parse error. If the XML is malformed, a clear message describes the problem — often an unclosed tag — instead of producing broken JSON.
  5. Copy or download. Take the JSON to your clipboard or save it as a .json file.

A worked example

Given this XML:

<book id="b1">
  <title>Clean Code</title>
  <tag>craft</tag>
  <tag>quality</tag>
</book>

the converter returns:

{
  "book": {
    "@id": "b1",
    "title": "Clean Code",
    "tag": ["craft", "quality"]
  }
}

Notice three rules in action at once: the id attribute became @id, the single title stayed a plain string, and the two tag elements collapsed into an array. That last point is worth remembering — a single occurrence stays an object while two or more become an array, so structure can change depending on the data.

How the mapping rules line up

XML constructJSON result
Element with childrenNested object
Repeated tag nameArray of objects or values
AttributeKey prefixed with @
Text alongside attributes/childrenStored under #text
Simple element, text onlyPlain string value

Why it stays private

Because parsing uses your browser's own DOMParser, the conversion runs entirely on your device. Your XML is never uploaded, logged or stored, which makes the tool safe for SOAP responses, RSS feeds, and config files that may carry credentials or internal details. Once the page has loaded it also works offline, so you can convert on a locked-down network or with no connection at all.

Try the XML to JSON Converter — free and 100% in your browser.

FAQ

Do I need to add an XML declaration at the top?

No. A well-formed document converts fine with or without the <?xml ?> declaration. What matters is that tags are properly closed and nested so the DOMParser can read the structure.

Why did a single element not become an array?

Arrays are created only when a tag name repeats within the same parent. One occurrence stays an object or string because that faithfully matches the source; if you need it always as an array, you can wrap it in code after converting.

Can I convert the JSON back to XML later?

Yes. Pair this tool with the JSON to XML Converter to round-trip in the other direction when a legacy system still expects XML.

What does the #text key mean in my output?

It holds the text content of an element that also has attributes or child elements. Splitting text into #text keeps it separate from those attributes and children so no data is lost or ambiguous.

Related free tools

Built by ByteVancer

ByteTools is a free product of ByteVancer, a software and web development studio building web apps, SaaS and custom software. If you need data pipelines, APIs or bespoke tooling built properly, explore what ByteVancer can do for your team.