json-tools .ru

XML to JSON

Parses XML with lxml and turns elements, attributes, and text into a JSON object — no external XSD schema or setup needed.

How attributes and text are stored

The result is an object with one top-level key named after the root tag. An element's attributes land under @attributes, and its inline text goes under #text when the element also has attributes or children; a plain text-only element with no attributes becomes just a string value.

Repeated tags

When an element has several child tags sharing the same name, they're automatically grouped into a JSON array under that name — so XML-style repeated elements are recognized correctly even without a dedicated wrapper tag.

Example: XML with attributes → JSON
XML
<book id="42" available="true">
  <title>Clean Code</title>
  <author>Robert C. Martin</author>
</book>
JSON
{
  "book": {
    "@attributes": {
      "id": "42",
      "available": "true"
    },
    "title": "Clean Code",
    "author": "Robert C. Martin"
  }
}
Format
XML → JSON
Source text Paste text or upload a file
Result Type is not detected yet
Statistics appear after formatting