XML To JSON

Convert XML text or a local .xml file into JSON in your browser. Paste XML, load the sample, upload or drop a file, choose pretty-print indentation or compact JSON, then copy or download the generated converted.json result.

XML to JSON
Drop XML File Here
Converted JSON
Output Size: 0 B JSON Content: 0 lines
Format Options
XML to JSON Conversion Guide
1. Paste XML Document
Paste your formatted XML structure or drag-and-drop a .xml file into the left panel.
2. Recursive Parsing
Our browser-sandbox recursive engine compiles XML tag hierarchies, attributes mapping keys, and CDATA payloads.
3. Extract JSON Result
Download the resulting validated JSON file or copy it instantly to your clipboard.

What the XML To JSON tool does

The XML To JSON tool converts XML markup into a JSON representation that is easier to inspect, copy, and reuse in JSON-based workflows. It is useful when you receive an XML sample from an API, feed, configuration export, test fixture, or documentation page and want to see the same hierarchy as JSON without writing a one-off parser.

The current Digital Domain Kit implementation runs the visible conversion in the browser. The page reads pasted XML, the built-in sample, an uploaded XML file, or the first file dropped onto the input panel. When you click Convert, JavaScript parses the XML with the browser's DOMParser, walks the resulting document tree, builds a plain JavaScript object, and serializes that object with JSON.stringify. The generated output appears in the JSON panel where it can be copied or downloaded as converted.json.

This converter is best for inspection, cleanup, and lightweight format translation. It is not a schema validator, XML security scanner, database migration tool, or guarantee that the resulting JSON matches a specific API contract. XML and JSON have different data models, so some structures need review after conversion, especially attributes, repeated elements, namespace prefixes, mixed text and element content, comments, processing instructions, and CDATA.

How to use the converter

  1. Paste XML into the XML to JSON input area, click Sample, choose Upload XML File, or drag a local XML file onto the input panel.
  2. Leave Pretty Print JSON enabled when you want readable multi-line JSON, or turn it off when you want compact JSON.
  3. If pretty printing is enabled, choose an indentation size of 2, 4, or 8 spaces.
  4. Choose whether to keep the visible Unescape Unicode Characters and Unescape Forward Slashes options enabled. They post-process the JSON string after serialization.
  5. Click Convert. Valid XML produces JSON in the output panel; invalid XML shows an XML parsing error message.
  6. Check the output size and line count below the JSON textarea.
  7. Use Copy or Download after you have reviewed the converted JSON.

Inputs, outputs, and verified behavior

The input must be parseable XML. A normal XML declaration such as <?xml version="1.0" encoding="UTF-8"?> is accepted, but the parser still needs one well-formed document element. Blank input clears the output and resets the displayed size and line count. If the browser parser reports a syntax problem, the page displays an error and does not keep a stale converted result in the output textarea.

Item What the tool does Important limitation
Text input Uses the current contents of the XML textarea. Malformed XML stops conversion instead of trying to repair the document.
File input Reads a selected or dropped file as text with FileReader. The interface accepts XML file types, but there is no separate streaming mode for very large files.
Parsing Uses browser DOMParser with application/xml. Behavior can depend on browser XML parsing rules and available memory.
Attributes Places attributes inside an @attributes object on the element. Attribute order should not be treated as meaningful JSON data.
Repeated elements Turns repeated child elements with the same tag name into an array. A single occurrence remains a single value, so consumers may need to normalize array fields.
Text values Returns simple text-only elements as strings, numbers, booleans, or empty strings. Numeric-looking strings such as prices or identifiers may become JSON numbers.
Download Creates a browser Blob with MIME type application/json. The current downloaded filename is fixed as converted.json.

Example XML and JSON output

The built-in sample is a small store catalog. It has a root store element with attributes, two repeated product elements, nested text fields, prices, and repeated tag children. With pretty printing enabled, the result shows how the current mapping works.

<store name="Digital Marketplace" location="Cloud Cluster">
  <product id="p101">
    <name>Ergonomic Chair</name>
    <price>320.00</price>
    <tags>
      <tag>Premium</tag>
      <tag>Ergo</tag>
    </tags>
  </product>
</store>

The converted JSON does not wrap the whole result in a top-level store key. Instead, the parsed document element becomes the top-level object. The root attributes are placed under @attributes, the repeated product elements become a product array when there is more than one product, and repeated tags become a tag array.

{
  "@attributes": {
    "name": "Digital Marketplace",
    "location": "Cloud Cluster"
  },
  "product": {
    "@attributes": {
      "id": "p101"
    },
    "name": "Ergonomic Chair",
    "price": 320,
    "tags": {
      "tag": [
        "Premium",
        "Ergo"
      ]
    }
  }
}

That example also shows a conversion detail that matters in real work: 320.00 is numeric-looking text, so the tool serializes it as the JSON number 320. That may be fine for calculations, but it can be wrong if the decimal formatting is part of a display value, a fixed-precision price, an identifier, or a code. Review the result before handing it to another application.

How XML structures are mapped

XML can represent data through elements, attributes, text nodes, namespaces, comments, CDATA sections, and processing instructions. JSON has objects, arrays, strings, numbers, booleans, and null. Because those models are not identical, every XML-to-JSON tool has to choose a mapping. This page uses a direct tree-walking mapping rather than a schema-aware conversion.

XML pattern Current JSON representation Review tip
<item id="7">Book</item> {"@attributes":{"id":"7"},"#text":"Book"} Text is stored as #text when an element also has attributes.
<tag>a</tag><tag>b</tag> {"tag":["a","b"]} Repeated siblings become arrays only after the second matching element appears.
<active>true</active> {"active":true} Lowercase and uppercase boolean-looking text is converted to a boolean.
<count>12</count> {"count":12} Numeric-looking text is converted with JavaScript Number().
<empty></empty> {"empty":""} Empty elements become empty strings, not null.
Comments or processing instructions Not represented in the generated object. Do not use this converter if comments are meaningful documentation that must survive.

Formatting options explained

Pretty Print JSON controls whether the tool calls JSON.stringify with indentation. When enabled, the indentation selector passes 2, 4, or 8 spaces. When disabled, the output is compact and the indentation selector is disabled. Compact JSON is useful when the result will be pasted into a system that ignores whitespace or when you want a smaller string for temporary transport.

Unescape Unicode Characters replaces JSON unicode escape sequences such as \u00e9 with the corresponding character. This can make names, labels, and non-English text easier to read in the output panel. It does not change the parsed XML tree; it is a string-level cleanup after JSON serialization.

Unescape Forward Slashes removes escaped forward slashes where they appear in the serialized JSON string. That is mostly a readability option for URLs and paths. JSON parsers generally accept either escaped or unescaped forward slashes, so this setting usually affects appearance rather than the data model.

The page also shows a Preserve CDATA Sections switch. In the active browser implementation, CDATA is read through the DOM as text content, so the <![CDATA[ ... ]]> wrapper is not meaningfully retained in the JSON output. Treat CDATA content as text after conversion and verify any markup-like content inside it before reusing the result.

When XML-to-JSON conversion helps

Converting XML to JSON is often helpful during API migration, debugging, documentation, and quick comparison work. For example, an older service may still return XML while a newer client expects JSON examples. A sitemap, RSS fragment, SOAP response sample, or configuration export may be easier to scan once repeated elements become arrays and nested elements become JSON objects.

The converter is also handy as a first inspection pass. You can paste a small XML fragment, see where attributes land, check which fields become arrays, and decide whether a downstream script needs additional normalization. If the output needs more JSON cleanup, use the JSON Beautifier for readability or the JSON Validator to check JSON syntax after manual edits.

For reverse work, the related JSON to XML tool can help when you need to move a JSON-shaped sample back toward XML. If your data is really tabular instead of hierarchical, tools such as CSV to JSON, JSON to CSV, or JSON to YAML may match the task better than forcing everything through XML.

Limitations to check before using the result

Use the generated JSON as a practical conversion result, not as proof that the source document follows a business schema. The tool does not read XSD files, DTD rules, Relax NG schemas, custom namespace contracts, or API-specific documentation. It also does not preserve XML comments, processing instructions, document type declarations, or formatting whitespace as meaningful data.

Mixed content needs special care. XML such as <p>Hello <strong>world</strong> today</p> combines text and child elements in an order-sensitive way. The current mapping focuses on attributes, text-only nodes, and child elements, so rich document-style XML may lose the exact reading order. This tool is better suited to data-style XML than to prose documents where inline markup matters.

Namespaces also need review. The browser exposes element names and attribute names as parsed node names, which can include prefixes such as atom:title. The converter does not resolve namespace URIs into a custom JSON structure. If a receiving application depends on namespace semantics, compare the output with that application's expected JSON format before using it.

Large XML files are limited by browser memory and responsiveness because the page reads the file into the textarea and parses it as one document. There is no streaming parser, chunked upload, background queue, or server-side batch conversion in the visible workflow. For very large feeds or exports, use a local script or dedicated data-processing tool that can stream and validate the document safely.

Privacy and workflow notes

The visible conversion path runs in your browser against the text or file you provide. The active conversion code does not show an XML upload step for the main conversion, although the page may still load normal site assets and optional reCAPTCHA scripts depending on site settings. Avoid pasting private keys, access tokens, unreleased customer data, or confidential XML exports unless your own policy allows using that data in a browser-based tool.

A careful workflow is to start with a short representative sample, inspect the JSON shape, then convert the full snippet once you understand the mapping. Keep the original XML until the converted JSON has been checked in the system that will use it. For production migrations, compare counts, required fields, numeric precision, boolean fields, arrays, and attributes before replacing the original source.

Related Tools

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us