Predictable mapping
Attributes use an @ prefix, repeated elements become arrays, and text-only content uses #text. Mixed content with child elements is rejected to prevent loss of text order.
Bounded and defensive
Input is limited to 10 MB, 100,000 XML nodes and 128 nesting levels. DTD and ENTITY declarations are rejected instead of resolving external or custom entities.
Need the reverse conversion? Convert JSON to XML.
When conversion is rejected
XML with mixed text and child elements is rejected because a plain JSON object cannot retain the original text order. Undefined entities, duplicate attributes, malformed quotes and closing tags are rejected. Attribute values containing a greater-than sign are supported.
Element names that resemble JavaScript properties
Elements named constructor, toString or __proto__ are kept as ordinary JSON keys, including repeated elements. XML comments and processing instructions are rejected rather than silently removed, because this mapping has no field for that metadata.
Namespace prefix validation
Prefixes must be declared in scope. Attributes with different prefixes but the same expanded namespace name are rejected as duplicates. Reserved xml and xmlns bindings are validated. Namespace declarations remain explicit @xmlns keys in JSON; verify the receiving system’s schema.
Indented XML versus significant whitespace
Pretty-printed XML such as <root><a>one</a><b><c/></b></root> can be converted even when text appears inside one sibling and nested elements appear in another. These are separate parent elements, not mixed content. Ordinary indentation between child elements is ignored in this JSON mapping.
When xml:space means the file must stay XML
With xml:space="preserve", even whitespace around child elements may be meaningful. If that preserved whitespace is interleaved with children, conversion stops rather than silently discarding it. A child with xml:space="default" can reset inherited preservation. If you need to retain the exact document structure, use XML formatting rather than conversion; for compatible structured data, see JSON to XML.