Skip to main content
SlapMyWeb
Skip to tool
Conversion

XML to JSON

Convert XML documents to JSON format using the browser DOM parser. Handles attributes, nested elements, and text content.

Click Convert or press Ctrl+Enter...

What is XML to JSON Converter?

XML to JSON is a conversion tool that transforms XML (Extensible Markup Language) documents into JSON (JavaScript Object Notation) format. It uses the browser's built-in DOMParser for reliable XML parsing, converts element attributes to @attribute keys, preserves text content as #text values, and automatically detects arrays when multiple sibling elements share the same tag name. Ideal for converting API responses, config files, or data feeds from XML to JSON.

How to Use XML to JSON Converter

  1. 1

    Paste your XML

    Enter or paste XML content into the left text area. Click Load Example for a sample document.

  2. 2

    Click Convert

    Press Convert or Ctrl+Enter to parse the XML and generate JSON output.

  3. 3

    Review the JSON

    The formatted JSON appears in the right panel. Attributes appear as @attr keys, text content as #text.

  4. 4

    Copy the result

    Click Copy to copy the JSON to your clipboard for use in your code or APIs.

Features

  • Browser DOMParser for reliable XML parsing
  • Attributes converted as @attribute keys
  • Text content preserved as #text values
  • Automatic array detection for repeated siblings
  • Handles nested elements of any depth
  • XML declaration and processing instructions handled
  • Clear error messages for malformed XML
  • Pretty-printed JSON output with 2-space indentation

Related Tools

Frequently Asked Questions

How are XML attributes handled?+
XML attributes are converted to JSON keys prefixed with @. For example, <item id="1"> becomes {"@id": "1"} in the JSON output.
How is text content handled?+
For elements with only text content and no attributes, the text becomes a plain string value. For elements with both attributes and text, the text is stored under the #text key.
Does it handle XML namespaces?+
Namespace prefixes are preserved in element and attribute names as-is. For example, <ns:element> becomes a key named "ns:element" in JSON.
How are repeated elements handled?+
When multiple sibling elements share the same tag name, they are automatically grouped into a JSON array.
What about CDATA sections?+
CDATA content is treated the same as regular text content and included in the text value of the parent element.
Can I convert JSON back to XML?+
Yes, use our JSON to XML converter at /tools/json-to-xml for the reverse conversion.
Is there a file size limit?+
No hard limit. The browser DOMParser can handle large XML documents, though very large files (over 10MB) may be slow depending on your device.
Does it handle self-closing tags?+
Yes. Self-closing tags like <br/> or <item attr="val"/> are handled correctly and appear as empty objects or attribute-only objects in the JSON output.