Updated · Built and checked by the PlinzoTools team, formulas tested against published sources
Convert well-formed XML into a structured JSON object.
{
"user": {
"@id": "42",
"name": "Ada"
}
}This tool parses well-formed XML into a JSON object -- element attributes become "@"-prefixed keys, repeated child elements collect into a JSON array, and text content becomes the element's value or a "#text" key when the element also has attributes or children.
Paste well-formed XML. The equivalent JSON structure appears instantly, wrapped in the root element's tag name.
The parser walks the XML tree recursively: a leaf element with only text content becomes a plain string value; an element with attributes or child elements becomes a JSON object, with attributes as "@name" keys and repeated child tags collected into an array automatically.
<user id="42"><name>Ada</name></user> converts to {"user": {"@id": "42", "name": "Ada"}}.
To go the other direction, see the JSON to XML Converter. To just reformat XML without converting it, use the XML Formatter.
Consider a hypothetical document with a root element called catalog, containing two item elements. Each item has an sku attribute and a name child, and the second item also has a price child. The result is an object with one key, catalog, whose value holds a key named item. Because the tag repeats, item is an array of two objects. Each object has an "@sku" key from the attribute and a name key with the text. Only the second one has price. Notice that all values are strings: a price written as 9.99 in the XML appears as "9.99" in quotation marks, since XML itself has no number type.
An array only forms when a tag repeats. If a catalog contains just one item, that item is a plain object, not an array with one entry. Code that reads the result and loops over the items will work for two items and break for one, which is a frequent surprise. When you build software on top of the JSON, normalize this yourself by wrapping a non-array value in an array before you loop. The same is true for a document that sometimes has zero, one or many repeated children.
When an element has attributes or children and also text, the text is collected under a "#text" key after trimming outer whitespace. Text that is broken up by child elements, as in a sentence with a bold word in the middle, is joined into a single string, so the position of the child element within the text is lost. This converter suits data-style XML, such as records and configuration files, better than document-style XML with inline formatting.
If you see a message about a malformed opening tag, look for a stray character before the root element, a DOCTYPE declaration, or single-quoted attributes. A message about a missing closing tag names the element that was left open, which makes it easy to find the typo. Check the nesting near that tag, and make sure the case matches, because closing tags are case sensitive.
Use the result as a readable view of the data, or as input to code that expects JSON. Because attribute keys begin with an at sign, you will need bracket notation to access them in most programming languages. Consider renaming those keys if your consumer expects plain field names.
No -- namespace prefixes are treated as a literal part of the tag name rather than resolved against a namespace URI, which covers most everyday XML but not namespace-heavy documents like SOAP.
Comments and processing instructions are stripped before parsing, since they have no meaningful JSON equivalent.
Multiple child elements sharing the same tag name are automatically collected into a JSON array under that key, rather than overwriting each other.
Arrays are created only when a tag repeats under the same parent. One occurrence is a plain object, so wrap it in an array in your own code if you need consistent handling.
No. XML has no types, so all values are strings, including numeric and true or false values.
The parser only recognizes attributes with double quotes. Change single quotes to double quotes.
It is stored under a key named #text, next to the attribute keys that begin with an at sign.
Reference: MDN Web Docs