Skip to content
Utiloom

XML to JSON Converter

Convert bounded XML into explicit compact or order-preserving JSON with safe scalar, whitespace, comment, and export policies.

LocalNo retention

Reviewed July 13, 2026

Guide, examples, and validation Show

About this tool

Parse XML into structured JSON when inspecting feeds, payloads, configs, or imported content.

XML to JSON Converter turns an XML document into JSON using the fast-xml-parser library, with two output shapes to choose from. Compact object mode produces the familiar property-style JSON where attributes sit under an @attributes key, element text under #text, and repeated same-name children become arrays. Ordered nodes mode keeps the exact document order of mixed siblings by emitting arrays of node records, with attributes stored under :@. Three switches control whitespace trimming, whether comments are kept as #comment entries, and whether numbers and booleans are inferred from text. Every conversion is re-parsed from the produced string and compared with the in-memory result before it is shown, and the panel reports element, attribute, depth, and JSON node counts alongside any policy warnings.

  • Offers compact property-oriented JSON and ordered node arrays that preserve order between differently named siblings.
  • Represents namespaces, attributes, text, CDATA, comments, and repeated elements with explicit documented keys.
  • Rejects malformed XML and DOCTYPE declarations, bounds document and JSON structure, and reparses every JSON result before export.

How to use XML to JSON

The input box loads with a small sample XML so you can see the mapping straight away; replace it with your own document of up to 2,000,000 characters. Choose Compact object or Ordered nodes under JSON representation. Turn on Preserve surrounding text whitespace if leading or trailing spaces in text nodes matter, Include XML comments if you want them carried over, and Infer booleans and numbers if values like 42 or true should become JSON scalars rather than strings. Press Convert. If the XML is malformed or contains a DOCTYPE, the error names the problem and no output is produced. When it succeeds, read the warnings under the output, check the badges for element and attribute counts, then copy the result or click the JSON download button.

When this tool is useful

  • An integration developer inspecting a SOAP or REST response that arrived as XML before writing the JSON mapping code.
  • A data analyst converting an RSS or Atom feed export into JSON to load it into a notebook or spreadsheet tool.
  • A DevOps engineer reading a Maven pom.xml or .NET config to compare settings across environments in a JSON diff tool.
  • A content migrator moving a CMS export with mixed text and inline tags, where sibling order must survive.
  • A QA engineer checking that repeated <item> elements become a real JSON array instead of a single object.

Practical tips

  • Use Ordered nodes whenever text and child elements are interleaved, because compact mode groups by name and loses that ordering.
  • Turn off Infer booleans and numbers for IDs, ZIP codes, and version strings; a leading zero or a 20-digit number would otherwise be altered or rejected.
  • DOCTYPE declarations are refused on purpose; strip the DTD and any entity definitions before pasting.
  • A single element that appears once becomes an object, not a one-item array, so consuming code should handle both shapes.
  • The XML declaration is dropped as metadata and will not appear in the JSON; do not look for an encoding key.

Examples you can test

Load an example, compare the result with the expected output, then replace it with your own input.

Compact mapping with an attribute

Example input

<book id="7"><title>Dune</title><title>Dune Messiah</title></book> with inference off

Expected output

{"book":{"@attributes":{"id":"7"},"title":["Dune","Dune Messiah"]}}; with inference on, id becomes the number 7

Two same-name children collapse into an array; a single title would have been a plain string instead.

Ordered nodes preserve mixed content

Example input

<p>Hello <b>world</b>!</p> with Ordered nodes and Preserve surrounding text whitespace on

Expected output

The p entry holds an array: a #text record 'Hello ', a b node containing 'world', then a #text record '!'

Compact mode would give you #text and b as separate keys with no way to know which came first.

Validation checklist

  • Confirm the document is under 2,000,000 characters and contains no DOCTYPE.
  • Check that repeated elements produced arrays and single elements produced objects as your code expects.
  • Compare a few numeric-looking values before and after when scalar inference is on.
  • Read every warning shown under the output before copying the result.
  • Check that the element and attribute counts roughly match the source document.

Frequently asked questions

Does this preserve XML attributes?

Yes. Attributes are preserved with an attribute prefix in the output JSON.

Can I convert very large XML files here?

Input is limited to 2,000,000 characters, 200,000 XML nodes, 100,000 elements, 200,000 attributes, and 128 levels. JSON output is limited to 300,000 nodes and 5,000,000 characters.

How are XML attributes represented in the JSON output?

Compact JSON groups original attribute names below "@attributes". Ordered JSON stores attributes in a ":@" record alongside the ordered node entry.

Does the converter handle XML namespaces?

Namespace prefixes are preserved in the JSON keys as-is, so <ns:element> becomes a key named ns:element. The namespace URI declarations are included as attributes.

What happens with CDATA sections in the XML input?

CDATA content is extracted as a plain text string in the JSON output, with the CDATA wrapper removed so the value is ready for direct use.

Related tools

Keep the workflow moving

Continue with tools that handle a related input, output, or validation step.

Developer

JSON Formatter

Validate strict JSON and create bounded review or export views.

Local
Developer

XML Formatter

Format and structurally verify bounded XML.

Local
Developer

CSS Formatter

Format CSS, SCSS, or Less with stable output verification.

Local
Developer

cURL to Fetch & Axios Converter

Convert curl commands to fetch or axios code locally.

Local