XML to JSON

Instant conversion

Paste any XML document and get clean, indented JSON output. Repeated sibling elements are automatically converted to arrays. Runs entirely in your browser — especially useful for inspecting bank-returned pain.002 responses and other ISO 20022 payment messages.

XML input
JSON output

Output will appear here

Conversion rules

  • XML elements Each XML element becomes a JSON key. Nested elements become nested objects.
  • Repeated elements Sibling elements with the same tag name are automatically converted to a JSON array.
  • Text content Element text content becomes the string value of the corresponding JSON key.
  • Self-closing tags Self-closing elements (<tag />) become null values in JSON.
  • XML declarations The <?xml ?> declaration and processing instructions are stripped from the output.

Common use cases

  • Inspecting ISO 20022 pain.002 Payment Status Report responses from banks
  • Converting SEPA payment XML files to JSON for logging and debugging
  • Parsing legacy XML APIs when migrating to JSON-based systems
  • Quickly reading the structure of an unfamiliar XML document during development

Dev snippet — XML to JSON (browser)

function xmlToJson(xml) {
  const parser = new DOMParser();
  const doc = parser.parseFromString(xml, "application/xml");
  function nodeToObj(node) {
    if (node.nodeType === Node.TEXT_NODE) return node.nodeValue?.trim() || null;
    const obj = {};
    for (const child of node.childNodes) {
      const val = nodeToObj(child);
      if (val === null) continue;
      const key = child.nodeName;
      if (key in obj) {
        obj[key] = [].concat(obj[key], val);
      } else {
        obj[key] = val;
      }
    }
    return obj;
  }
  return nodeToObj(doc.documentElement);
}