XML to JSON Converter for SOAP, API Payloads & Tag Attributes
Paste a SOAP response or XML API payload and read it as JSON, or write JSON objects back into tags and attributes in your browser. The compact mapping is predictable, but one child and two repeated children produce different JSON shapes, and mixed text order is not kept.
How this XML ↔ JSON converter behaves
Tags become keys, attributes go to _attributes
Each element maps to a key named after its tag. <user id="7">Ann</user> becomes { user: { _attributes: { id: "7" }, _text: "Ann" } }, so attributes and text never collide with child tags.
One child is an object, two become an array
A single <item> stays an object; two <item> siblings become a JSON array. When a response drops from two rows to one, the shape changes, so guard for both in your client code.
Declarations, comments and CDATA keep their own keys
_declaration, _doctype, _comment and _cdata appear as siblings of the root element. CDATA is read as raw text, and all four are written back when converting JSON to XML.
Text is kept, but its position is not
In compact mode text on both sides of a child collapses into one _text array: <r>before<a>1</a>after</r> becomes _text: ["before", "after"], and writing it back produces beforeafter<a>1</a>. Use element-only content when you need a clean round trip.
Namespaces and special characters are handled
xmlns / xmlns:p stay as ordinary attributes, and <, & and > in text are escaped on output and unescaped on input. Files are read and converted locally; nothing is uploaded.
XML ↔ JSON conversion FAQ
Why does the JSON shape change when only one row comes back?
Because the converter uses xml-js compact mode: repeated same-name children collapse into a JSON array, while a single child stays an object. A feed with two <item> entries gives item: [...], one entry gives item: {...}. Normalize to an array before reading fields on the client.
How are attributes and element text represented?
Attributes go into _attributes and text into _text, for example <user id="7">Ann</user> → { user: { _attributes: { id: "7" }, _text: "Ann" } }. Text is always a string, even for <n>42</n>, and an empty element becomes {}.
Can I convert a top-level JSON array to XML?
No. The JSON root must be a single object; an array root produces invalid element names such as <0><r>a</r></0><1><r>b</r></1>. Wrap the array in a root object, for example { "items": { "item": [...] } }.
Are declarations, comments, CDATA and DOCTYPE kept?
Yes, as dedicated keys: _declaration, _comment, _cdata and _doctype. Reading yields _comment: " hi " (with the surrounding spaces) and _cdata: "raw <x>"; converting back writes <?xml ...?>, <!--hi-->, <![CDATA[...]]> and <!DOCTYPE r>.
What happens to text mixed with child elements?
Compact mode collects the text pieces into a _text array and drops their positions. <r>before<a>1</a>after</r> becomes { r: { _text: ["before", "after"], a: { _text: "1" } } }, and writing it back gives <r>beforeafter<a>1</a></r>. The non-compact mapping keeps order, but this page is fixed to compact mode.
How are namespaces and special characters handled?
Namespace declarations are preserved as plain attributes (xmlns, xmlns:p), and prefixed tags keep the prefix in the key (p:a). Text escapes <, & and > on write and unescapes entities on read; attribute values only escape quotes, so a raw < or & inside an attribute can still produce invalid XML.
What errors can appear, and is my data uploaded?
Multiple root elements fail with 'Text data outside of root node', a mismatched closing tag fails with 'Unmatched closing tag', and a scalar root fails with 'The JSON structure is invalid'. The box turns red and no partial output is written. Everything runs in the browser and files are never uploaded.

