{ } JSON Workbench0 network requests. Check DevTools

"XML to JSON":{ }

Paste XML and get JSON instantly. Attributes are prefixed with @_, repeated sibling elements collapse into arrays, and text content maps to a value key. Powered by fast-xml-parser, running 100% in your browser. No upload, no signup.

What is XML to JSON conversion?

XML is verbose, schema-heavy markup common in enterprise, SOAP, and legacy feeds; JSON is the compact, JS-native format modern APIs use. Converting XML to JSON makes the data trivial to consume in web apps. The catch is attributes, mixed content, and the single-vs-array ambiguity, which this tool handles predictably by prefixing attributes with @_ and text nodes with #text.

Edge cases & gotchas

  • Single-vs-multiple ambiguity: one child = object, many = array. Downstream code should normalize (always treat as array), since the shape depends on the data.
  • Attributes need the @_ prefix or they'd collide with element names.
  • Namespaces: prefixes like soap: clutter keys; there's no clean JSON analog.
  • Types: XML is all strings; numbers and booleans stay quoted unless type inference is enabled.
  • Empty / self-closing tags (<active/>) become an empty string or empty object.
  • Non-object root / bare value: wrapped in <root> so the output is valid JSON.

XML → JSON mapping rules

XML constructJSON result
Elementkey
Attribute@_name key
Repeated siblingsarray
Text content#text
CDATAplain-text string
Self-closing tagempty string
Non-object rootwrapped in <root>

How to use

  1. Paste XML into the Input pane, or upload a .xml file.
  2. Convert: fast-xml-parser maps elements to keys and attributes to @_ keys.
  3. Repeated siblings become a JSON array; a non-object root is wrapped in <root>.
  4. Choose indentation or minify.
  5. Copy the result or download it as .json.

Examples

Basic nesting

Input
<book><title>JSON Basics</title><author>A. Smith</author></book>
Output
{
  "book": {
    "title": "JSON Basics",
    "author": "A. Smith"
  }
}

Attributes + repeated elements → array

Input
<library>
  <book id="b1" lang="en"><title>JSON Basics</title></book>
  <book id="b2" lang="fr"><title>XML Guide</title></book>
</library>
Output
{
  "library": {
    "book": [
      { "@_id": "b1", "@_lang": "en", "title": "JSON Basics" },
      { "@_id": "b2", "@_lang": "fr", "title": "XML Guide" }
    ]
  }
}

Mixed content (attribute + text)

Input
<price currency="USD">42.00</price>
Output
{ "price": { "@_currency": "USD", "#text": "42.00" } }

FAQ

Why convert XML to JSON?

JSON is lighter, easier to parse in JavaScript, and API-friendly compared to verbose XML.

How are XML attributes handled?

Prefixed with @_ (e.g. @_id) to distinguish them from child elements.

How are repeated elements handled?

Two or more similar siblings become a JSON array; a single occurrence stays an object.

What about CDATA?

Extracted as plain text; the wrapping markup is stripped.

Can I convert complex / SOAP / WSDL XML?

Yes, though namespaces (soap:Envelope) carry into keys and may need cleanup.

Is my data uploaded?

No. fast-xml-parser runs in your browser; verify zero requests in DevTools. Going the other way? Try CSV to JSON or YAML to JSON.

Related tools