XML to JSON mapping guide

Does XML to JSON preserve CDATA, comments, and mixed-text order?

Answer for this converter: No. In five live tests, ParseBloom omitted CDATA content and comments. It combined ordinary text around a child element into one _text value, so the child's original position could not be reconstructed. Keep the XML source when those details matter.

Tested 27 October 2026 in the live ParseBloom XML to JSON converter. These results describe this tool, not every converter.

One diagram: what survives this mapping

XML node types and JSON outputOrdinary text and child elements are kept, while CDATA and comments are omitted. Separate ordinary text segments are joined before the child is added to JSON.XML input nodestext + <b>child</b> + text<![CDATA[...]]> + <!--...-->Order and node types exist in XMLParseBloom JSON_text + bCDATA and comment omittedMixed-text order unavailable

The browser's XML parser distinguishes node types. ParseBloom's current mapper reads ordinary text nodes and child elements, but does not add CDATA or comment nodes to its JSON object. This is an observed limit to check before using the output in a migration.

Five copyable tests and observed outputs

Each synthetic XML sample was typed into the public converter and converted on 27 October 2026. JSON is compacted here; the tool displays indented output.

1 · CDATA only
<r><![CDATA[A < B]]></r>
Observed JSON
{"r":""}

The CDATA characters do not appear. A successful parse does not prove that all text survived.

2 · Text plus CDATA
<r>left<![CDATA[right]]></r>
Observed JSON
{"r":"left"}

Ordinary text survives; the CDATA segment does not. This isolates which node type was dropped.

3 · Comment between text
<r>alpha<!-- note -->beta</r>
Observed JSON
{"r":"alphabeta"}

The comment is omitted, and the ordinary text nodes join. The result cannot show that a comment separated them.

4 and 5 · Different XML order
<p>before<b>bold</b>after</p>
<p>beforeafter<b>bold</b></p>
Observed JSON for both
{"p":{"_text":"beforeafter","b":"bold"}}

The child moves relative to the final text, yet both inputs map to the same object. JSON alone cannot tell which order was used.

Two inputs collapse to one result

Different XML child positions produce identical JSONIn case A, the bold child is between before and after. In case B, the child follows beforeafter. Both map to the same JSON text and b properties.A · before → bold child → after{"_text":"beforeafter","b":"bold"}B · beforeafter → bold child{"_text":"beforeafter","b":"bold"}

The matching outputs are an information-loss test, not a guess about how the original XML was laid out.

A decision check before you use the JSON

If the next system needs only ordinary element text and child values, the output may be enough. If it must reproduce documentation, HTML-like prose, XML comments, or CDATA payloads, retain and process the XML source with a mapping that explicitly records those node types and their sequence.

Test an actual document containing the features you depend on. Compare its XML source against JSON field by field. The two distinct mixed-content inputs above are a quick check: identical output proves a reverse conversion cannot recover their differing order from this JSON shape.

A different library may keep CDATA as text or represent comments with explicit keys. Check that library's mapping and run the same fixtures; do not transfer this result by assumption.

Watch the five-test walkthrough

If the player does not load, watch the video on YouTube.

Questions behind these tests

Can I reconstruct where a child appeared among text segments?

Not from this converter's JSON. The two tested <p> inputs produce the same object despite different child positions. A public developer question about reconstructing node order shows why the distinction matters.

Does CDATA become ordinary text?

Not in the current ParseBloom mapping: the CDATA-only test produced an empty string. Other tools can make a different choice; a public CDATA conversion question shows the result depends on the mapper. Preserve XML if you cannot afford to lose the content.

Also see the attribute and leading-zero guide and the single-versus-array guide.

Run the XML to JSON converter