Skip to content
TinySolve

XML to JSON

Convert an XML document or API response into JSON you can work with.

Runs in your browser — nothing you type is sent anywhere

Indent

JSON

The result appears here as you type. Nothing is sent anywhere — the work happens in this page.

Attributes become keys prefixed with @_, and an element’s text becomes #text when it also has attributes or children. Repeated sibling elements become an array — but a single element cannot be told apart from a one-item list without a schema, so it stays a plain value.

About the XML to JSON

Plenty of systems still speak XML — SOAP services, RSS feeds, sitemaps, government APIs, older enterprise software — and almost everything you would write to consume them prefers JSON. This converts one to the other in your browser.

The conversion is not entirely mechanical, because XML can express things JSON cannot, and the choices a converter makes determine whether the output is usable. Attributes become keys prefixed with <code>@_</code>. An element that has text as well as attributes or children gets its text under <code>#text</code>. Repeated sibling elements become an array. Those are the fast-xml-parser conventions, chosen because they are the ones most people have already seen.

One ambiguity has no good answer and is worth knowing about. A list with two items becomes an array; a list with one item cannot be told apart from a plain value, so it becomes one. Any code consuming the result should handle both — this is inherent to XML, not a shortcoming of the converter.

Numbers and true/false are converted where it is unambiguous, and deliberately not where it is risky: a value with a leading zero stays a string, because a postcode, part number or phone number turned into a number has been corrupted. That is a far more damaging mistake than a number arriving as a string, and it can be turned off entirely.

Entities are decoded, CDATA is taken literally, comments and the declaration are dropped, and a malformed document is reported with the tag that is wrong rather than producing half-converted output. It all runs in your browser.

How to use the XML to JSON

  1. Paste your XML

    An API response, a feed, a configuration file or an export.

  2. Choose how values are treated

    Convert numbers and true/false, or keep everything as strings. Attributes can be dropped if only the structure matters.

  3. Read the JSON

    Attributes appear under @_ keys and mixed content under #text, so nothing from the original is silently lost.

  4. Copy or download

    Take it to the clipboard or save it as a .json file.

Frequently asked questions

Why do attributes have an @_ prefix?
Because JSON has no separate idea of an attribute, so they have to live alongside child elements without colliding with them. The @_ prefix is the fast-xml-parser convention, which is the one most people and libraries already expect.
Why is a single element not an array?
Because nothing in the XML says it should be. Two <item> elements are obviously a list; one is indistinguishable from a plain value without a schema. Code consuming the output should handle both — this is inherent to XML.
Why did my leading zeros survive?
Deliberately. "007" stays a string, because a postcode, part number or phone number silently turned into 7 is corrupted data — a much worse outcome than a number arriving as a string. Value conversion can be switched off entirely.
What is #text for?
An element with both text and attributes, like <price currency="GBP">42</price>, cannot be represented as a single value without losing one of them. The text goes under #text so nothing is dropped.
Is my XML uploaded?
No. The conversion happens in your browser using a small parser built for this, with no third-party library and no network request.