Developer Tools
XML to JSON converter.
Paste XML and get JSON, or paste JSON and get XML. Attributes, repeated elements, CDATA and entities are handled, and a malformed document tells you the line and column. Nothing leaves your browser.
Input
Converted output
Paste XML or JSON to convert it.
About this XML to JSON converter
XML and JSON do not map one-to-one: XML has attributes, mixed text and ordered repeated elements, while JSON has objects, arrays and typed scalars. This converter uses one fixed, reversible convention so the result is predictable.
Worked example
<order id="7">
<item sku="A1">Widget</item>
<item sku="B2">Gadget</item>
</order>
becomes
{
"order": {
"@id": "7",
"item": [
{ "@sku": "A1", "#text": "Widget" },
{ "@sku": "B2", "#text": "Gadget" }
]
}
}
Rules used
- Attributes become keys prefixed with
@. - Text in an element with no attributes or children becomes a plain string; otherwise it is stored under
#text. - Repeated siblings with the same name become an array in document order. A single child stays an object, so the shape can differ between documents with one item and many.
- CDATA sections and the five predefined entities plus numeric character references are decoded. Comments and processing instructions are dropped.
- Values stay strings unless you tick the type option, which turns
true,falseand plain numbers into JSON types. Long digit strings such as IDs stay as text. - JSON to XML reverses the convention. A top-level array is wrapped as
<root><item>elements, and key names that are not valid XML names are rejected rather than silently changed.
Limits
- Mixed content such as
<p>Hello <b>world</b></p>keeps the text together under#text, so the position of the inline element is lost. - Namespaces are kept as part of the name (
ns:tag) and not resolved. - DOCTYPE entity declarations are refused, which prevents entity-expansion output. Input is capped at 5 MB.
FAQ
Why is one element an object but two elements an array?
JSON has no way to know a single element could repeat. A lone child is an object and repeated siblings become an array. If your code needs an array every time, wrap it: [].concat(value).
Where did my XML attributes go?
They are keys that start with @, next to the element's children. Text sits under #text when an element has attributes or children.
Is my XML uploaded?
No. Parsing and conversion run in your browser and nothing is sent to a server.
Source
- Extensible Markup Language (XML) 1.0, W3C Recommendation: w3.org/TR/xml, for names, entities, CDATA and well-formedness.
- RFC 8259, The JSON Data Interchange Format: rfc-editor.org/rfc/rfc8259.