XML to JSON Converter
Convert XML to JSON with correct handling of attributes and repeated sibling elements as arrays. Paste XML, get valid JSON. Nothing is uploaded to a server.
Worked examples
- A simple element with two children
The everyday case: an XML config or SOAP-style response becomes a nested JSON object, keeping the root element as the top-level key.
- An element with an attribute
XML attributes carry data too; this converter keeps them as fields prefixed with @_ so they don't collide with child-element names.
- Repeated sibling elements become an array
When a tag repeats under the same parent, that's the signal most XML-to-JSON converters get wrong; this one turns it into a proper JSON array.
What this converter does
XML and JSON both represent structured, nested data, but XML uses tags and attributes where JSON uses objects, arrays and keys. This tool parses XML and converts it to JSON, turning nested elements into nested objects, repeated sibling tags into arrays, and attributes into prefixed fields — the same set of conventions most XML-to-JSON libraries settle on, applied consistently.
When you need it
- Reading a SOAP response, an RSS/Atom feed, or a legacy XML API's output in a JavaScript app that works natively with JSON.
- Debugging a deeply nested XML document by seeing its structure as JSON, which is often easier to scan than heavily indented tags.
- Converting XML-based config (some CI systems, some enterprise tools) into JSON for use with modern tooling.
Rules the converter applies
- The XML is validated first. Unclosed tags, mismatched closing tags, malformed attributes, more than one root element and undeclared entities stop the conversion with the line and column of the problem, rather than producing a best-effort guess.
- Each element becomes a JSON object, with the root tag as the single top-level key.
- Attributes become fields prefixed with
@_(so<user id="1">becomes{"user": {"@_id": "1"}}) — the prefix keeps an attribute likeidfrom colliding with a child element also namedid. - A tag that repeats under the same parent becomes a JSON array. A tag that appears exactly once stays a plain value or object; this is the detail that trips up hand-written XML parsers, since the same tag name can mean "one value" or "a list" depending on how many times it shows up in a given document.
- Text content of an element with no attributes and no children becomes a plain string or number value rather than a nested object.
XML and JSON side by side
| XML | JSON | Note |
|---|---|---|
| <a>1</a> | {"a": "1"} | Element text becomes a string value, never a number |
| <a><b>1</b></a> | {"a": {"b": "1"}} | Nested elements become nested objects |
| <a><b>1</b><b>2</b></a> | {"a": {"b": ["1", "2"]}} | Repeated sibling tags become an array |
| <a id="1"/> | {"a": {"@_id": "1"}} | Attributes get an @_ prefix |
Things to check after converting
- All attribute and text values come through as strings, since XML has no native number or boolean type; values such as
01234,0x1For1e3are kept exactly as written rather than being turned into numbers. Cast fields to the type your code expects afterward. - The
<?xml ...?>declaration is dropped, and comments are not converted. An element that mixes text and child elements (<p>Hello <b>bold</b> world</p>) is converted to a#textfield plus the child, and the text pieces are joined without the spaces around the child, so mixed-content documents such as XHTML do not survive the conversion intact. - When an element has both child elements and attributes, the attribute fields (
@_id) are listed after the children in the JSON. - XML namespaces (
<ns:tag>) are kept as part of the tag name literally; this converter doesn't resolve or strip namespace prefixes. - If a repeatable element should always be an array in your code, even with one occurrence, normalize that yourself — this converter can't infer your schema's intent from a single document.
Limits
Input is capped at 2 MB. Very large or very deeply nested XML documents (thousands of elements) parse correctly but may render slowly in the browser preview.
Frequently asked questions
- Is my XML uploaded anywhere?
- No. The conversion runs entirely in your browser; nothing is sent to a server.
- How are XML attributes represented?
- Each attribute becomes a field on the element's object, named with an @_ prefix so it can't collide with a child element of the same name.
- How does it decide something is an array?
- Any tag that appears more than once under the same parent is converted to a JSON array; a tag that appears once stays a plain object or value.
- What happens with malformed XML?
- The document is validated first, and unclosed or mismatched tags stop the conversion with the line and column of the problem.