Skip to content

Converter Tools

XML to JSON

Parses XML elements and attributes into nested JSON, useful when working with an API or config that uses XML.

  • Free
  • No sign-up
  • Runs in your browser

Guide

How XML and JSON structure data differently

XML describes data with nested elements in opening and closing tags, optionally with attributes. JSON uses objects, arrays and simple values. Both represent trees, but they do not map perfectly: XML has attributes and mixed text, while JSON has real arrays, numbers and booleans.

This converter uses a simple, element-only mapping. An element with no child elements becomes a text value. An element with children becomes an object keyed by the child tag names. If a tag name repeats among siblings, the values are collected into an array. The whole result is wrapped in an object keyed by the root element's name.

So Ada32 becomes an object named person containing name and age, each holding a string.

When you need to convert XML to JSON

Older systems, RSS and sitemap files, SOAP services and many configuration formats use XML, while modern JavaScript code and REST APIs prefer JSON. If you receive an XML response and want to inspect it, copy it into a front-end mock or feed it to a tool that only accepts JSON, conversion saves hand-typing.

It also helps you understand an unfamiliar XML document, since nested JSON often makes the hierarchy clearer. If the XML is hard to read, run it through the XML formatter first, and use the JSON formatter to reshape the output.

How to use the XML to JSON converter

  1. Paste your XML into the XML box. A small sample with a person, name and age is preloaded.
  2. The tool parses it with your browser's built-in XML parser.
  3. If the XML is not well-formed, the message "Invalid XML" appears in red where the output would be.
  4. Otherwise the JSON box shows the result, indented with two spaces and updating as you type.
  5. Click Copy to copy the JSON.

Parsing happens locally, so the XML is not uploaded. There is no file picker or download button.

What gets lost in the conversion

Because of the simple mapping, some information does not survive:

  • Attributes are ignored. In Pen, the id is not in the JSON. Move important values into child elements first.
  • Every value is a string, with surrounding whitespace trimmed.
  • Mixed content is dropped. If an element has both text and child elements, only the children are used.
  • A single child stays a plain value. An element becomes an array only once it repeats, so code reading the JSON must handle both cases.
  • Comments are not carried over, and namespace prefixes stay part of the key names.

Use the output as a reading and prototyping aid, and compare it with the source for production work. For the other direction, try JSON to XML.

Frequently asked questions

What happens to XML attributes?

They are not included. The converter looks only at elements and their text, so attributes such as id are dropped.

Why are some values arrays and others not?

A tag that appears more than once inside a parent is grouped into an array. A tag that appears once is a single value, so the structure can vary with the data.

Why do I get Invalid XML?

The browser's parser found a problem, such as a missing closing tag, an unquoted attribute or more than one root element. Fix the markup and the output returns.