XML to JSON
Convert XML to JSON format.
Loading…
About XML to JSON
Feeds, exports and older integrations still arrive as XML while your code wants JSON. The converter first checks that the document is well-formed, then maps it: attributes become keys that start with @_, sibling elements with the same name become an array, and text beside attributes goes under a #text key. Values stay as strings unless you tick the box that converts numbers and true or false, which keeps values such as 007 as text.
Features
- Attributes become keys with an @_ prefix
- Sibling elements with the same name become an array
- Text that sits beside attributes goes under a #text key
- Optional number and true/false conversion; zero-padded values, hex and exponents stay text
- Malformed XML is reported with a line and column
- CDATA sections and numeric character references are decoded
Limitations
- The document needs exactly one root element; two top-level elements are rejected.
- A single child element is not wrapped in an array, so a list that happens to hold one item looks like a plain value.
- Comments and the XML declaration are dropped, and custom entity declarations (<!ENTITY>) are refused.
- Text mixed in between child tags is joined under #text, so spacing and position around the tags are lost.
How it works
- Paste XML with a single root element into the XML Input panel.
- Tick Convert numbers and true/false if you want typed values; leave it clear to keep everything as text.
- Select Convert to JSON. Ticking or clearing the box runs it again.
- Read the indented result in the JSON Output panel, or the error message in the middle column.
- Copy it with Copy Output.
Example input
<book id="1">
<title>Auro Guide</title>
<tag>json</tag>
<tag>xml</tag>
</book>Frequently asked questions
- Each attribute becomes a key with an @_ prefix, so id="1" turns into "@_id": "1". If the element also has text, the text is stored under #text next to those keys. Namespace prefixes stay in the names.
- The converter only sees what is in the document. Repeated sibling tags are grouped into an array, while a lone tag stays a single value. If your code expects a list, wrap a lone value in an array after parsing.
- Tick it when you want 12 as a number and true as a boolean. Leave it clear to keep every value as text. Even when ticked, values like 007, 0x1F and 1e3 stay text, so identifiers are not damaged.
- An XML document has a single outermost element, and JSON needs one top-level key to hold it. Wrap the elements in a parent tag such as <data> and convert again.
- Custom entities defined in a DOCTYPE, written with the ENTITY keyword inside angle brackets, are not supported. Replace each entity with its literal text and convert again. Standard references such as & and 😀 are decoded as normal.
