XML to JSON Converter

Convert XML into an ordered JSON tree with attributes, namespaces and mixed text preserved. Reject malformed XML and external entity declarations.

Runs in your browser; input is not uploaded or saved. Limit: 1 MiB UTF-8.

How to use XML to JSON Converter

Turn XML into an explicit JSON tree that keeps element order, attributes and mixed text. This mapping avoids treating repeated tags as duplicate object keys and retains namespace identity even when a prefix is rebound inside the document.

  1. Paste XML or load the catalog sample. DTDs and entity declarations are rejected before XML parsing.
  2. Choose Convert to JSON. Correct malformed tags, undeclared prefixes or invalid attribute syntax if an error appears.
  3. Read the mapping rules below, then copy or download the JSON tree for your own application.

XML mapping, security and limitations

  • Each element becomes an object with name (qualified tag name), namespace (resolved URI or null), attributes (an ordered array of name, namespace and string value), and children (an ordered array of text strings or element objects).
  • Repeated elements remain separate children. Text, CDATA and whitespace inside the root are preserved; adjacent text/CDATA nodes are combined. Empty elements have an empty children array. No automatic number or boolean conversion occurs.
  • Namespace declarations are retained as attributes. Prefixes and resolved URIs are both included; default namespaces apply to elements, not unprefixed attributes.
  • Comments, processing instructions and the XML declaration are omitted. XML parser normalization of line endings and attribute values applies. This is a tree representation, not a byte-for-byte reversible serialization.
  • DOCTYPE and ENTITY declarations are rejected, including external entities and remote DTDs. Nothing is fetched, executed or inserted as HTML. Limits: 1 MiB input, 64 element levels, 20,000 element/text nodes and approximately 8 MiB of output.

Processing uses browser memory only. Nothing you enter is sent to a conversion service or stored by these tools. Downloads are saved by your browser, and copied results remain on your clipboard until replaced.

Practical examples

Attribute plus text

Input
<item id="7">Tea</item>
Result
An item node with an id attribute and children ["Tea"].

The attribute value remains the string "7", separate from the element text.

Repeated entries

Input
<list><item>A</item><item>B</item></list>
Result
The list has two item objects in its children array.

Both entries survive and their original order is preserved.

Mixed content

Input
<p>Hello <b>world</b>!</p>
Result
Children contain "Hello ", a b element, and "!" in that order.

Keeping text beside elements avoids losing the location of inline markup.

Frequently asked questions

How does this converter represent XML attributes and repeated child tags?

To avoid data loss from duplicate object keys, this tool produces an explicit JSON syntax tree where each element is an object with 'name', 'namespace', an ordered 'attributes' array, and an ordered 'children' array. Repeated sibling tags remain preserved in their original sequence rather than overwriting each other.

Are XML external entities (XXE) and remote DTDs processed?

No. For security, DOCTYPE and ENTITY declarations are rejected immediately before parsing. The tool does not resolve external network resources, execute entities, or insert unescaped markup, protecting against XML entity expansion vulnerabilities.

Does the converter automatically convert string values into numbers or booleans?

No. All text and attribute values are preserved strictly as strings. Automatic type coercion can inadvertently corrupt identifiers (such as postal codes with leading zeros like '01234' becoming '1234') or currency strings, so data typing is left to your application logic.

Related tools

Available

Image Compressor

Compress and optimize JPEG, PNG, and WebP images locally in your browser. Adjust quality, compare file sizes, resize dimensions, and batch download without server uploads.

Image Tools