XML to JSON

XML to JSON convert XML document XML attributes to JSON object XML array mapping
XML to JSON

Choose how XML becomes JSON

Paste XML or open a UTF-8 XML file. Select an attribute style and whether every child element should become an array. The result updates automatically. Read the conversion summary before copying or downloading the JSON, especially if the source mixes text with child elements.

Advertisement

There is no single universal mapping

XML supports attributes, text nodes, namespaces and ordered mixed content. JSON uses objects, arrays and primitive values. A conversion must choose conventions. This tool keeps the root element as the outer property, prefixes individual attributes with @ or groups them under @attributes, and stores direct text in #text when an element also has attributes or children. A plain text-only element becomes a string.

Worked example: identifiers stay strings

With prefixed attributes, <item id="007">Notebook</item> becomes an item object containing "@id": "007" and "#text": "Notebook". The leading zeros remain intact because the converter does not guess numeric types. Two item elements under one catalog become an item array. With “Always arrays,” a single child item also becomes a one-element array, which can make downstream code more predictable.

Advanced names, whitespace and values

Open Advanced options to change the attribute prefix or text property name. A blank prefix produces id rather than @id; setting the text name to text produces a plain text property. If an attribute, child element or direct-text field would share a name in the same object, conversion stops with a collision message. Choose a different name or attribute layout; no value is silently overwritten.

Preserve whitespace is the default. Trim removes surrounding whitespace from text and ordinary attribute values, leaving internal spaces unchanged. Indentation-only text between children remains omitted in either mode. XML namespace declarations always remain unchanged strings.

Optional value conversion recognizes lowercase true and false and JSON-style numbers, including decimals and scientific notation. Leading-zero identifiers such as 007, integers outside JavaScript’s safe range, negative zero, overflow and underflow remain strings. Dates and the word null remain strings too. Decimal numbers use JavaScript numeric precision and may lose formatting or precision. With whitespace preservation selected, a padded value such as space-42-space remains a string; choose Trim to make it eligible for conversion.

Repeated names and namespaces

Repeated siblings with the same qualified tag name are grouped in source order. Distinct sibling names become separate properties, so the original interleaving between different names is not represented. Namespace prefixes remain part of names, and namespace declarations are retained as attributes. This is a structural convenience mapping, not a namespace-aware schema conversion or an XML canonicalization algorithm.

Mixed content needs review

A paragraph containing text before and after an emphasized child cannot be faithfully represented by ordinary grouped properties alone. The tool combines its direct text segments into #text and displays a warning. Those segments no longer record where the child appeared between them. Comments and processing instructions are omitted. Whitespace-only indentation around child elements is ignored, while text in leaf elements is preserved.

Limitations and invalid input

Files must be UTF-8 and no larger than two megabytes. The parser rejects malformed XML, including unmatched tags or unescaped ampersands. DOCTYPE and entity declarations are rejected; the tool does not resolve external entities, retrieve schemas or validate a document against a DTD. A maximum of 30,000 elements and 100 nested levels bounds conversion work.

All processing stays in the browser. The output should be checked against the receiving application’s expected mapping before importing it. A valid JSON document can still have the wrong schema for that application, and this conversion is not guaranteed to round-trip to the original XML.

XML conversion FAQ

Will true become a JSON boolean?

By default, no. Enable value conversion in Advanced options to convert lowercase true and false and eligible numbers. Keep the default when exact textual values matter.

What happens to an empty element?

An element with no children or attributes becomes an empty string. An empty element with attributes becomes an object containing those attributes.

Related tools

Categories

Tags