The Complete Guide to Converting Between XML and JSON
Learn why XML-to-JSON is lossy by design, the three conventions for representing attributes and mixed content, and how to pick the convention your downstream tool expects.
1. Why XML-to-JSON Is Always Lossy
XML and JSON have different native concepts. XML has element order, attributes, mixed content (text interleaved with child elements), namespaces, and comments. JSON has neither attributes nor mixed content natively; everything is either a primitive, an array, or an object. Any XML-to-JSON conversion therefore projects extra XML features onto JSON conventions, and choosing the right convention depends on what your downstream tool expects.
The single most important convention choice is how to represent XML attributes. Without a rule, an attribute and a child element with the same name would collide destructively in the resulting JSON object. Establish the convention upfront and document it; that is the only path to clean downstream parsing.
2. The Three Common Conventions for Attributes
The Parker convention simply discards XML attributes and keeps only element text content, producing the smallest JSON. It is useful when attributes carry only redundant metadata. The BadgerFish convention prefixes every attribute with an at-sign so attributes and child elements never collide: an attribute named id becomes a JSON key @id. Text content lives in $ or $t. The GData convention places attributes into a nested $ object and text content into $t, preserving a clean separation.
ToolWise defaults to the GData convention because it integrates well with most frontend data layers, but you can switch the convention in the UI when your downstream parser expects Parker (lossy minimal) or BadgerFish (maximally lossless).
3. Element Order, Namespaces, and Mixed Content
Three structural features deserve special handling. Element order matters when you have multiple children with the same name (the converter produces a JSON array to preserve order). Namespaces are typically preserved verbatim with the original prefix, because flattening them loses information. Mixed content is the hard case: a paragraph of text interleaved with child elements must split the text into chunks that surround each child, otherwise the resulting JSON loses the text content entirely. The converter handles all three so that the round-trip from XML through JSON back to XML reconstructs the original document as closely as possible within the chosen convention.
4. When To Pick Lossy Versus Lossless
Pick the lossy Parker convention when the XML is configuration-shaped and attributes are merely redundant IDs. Pick BadgerFish when you need to round-trip the document through other tools that also expect the full-attribute representation. Pick the GData convention as the safe default for general-purpose API integrations where lossless fidelity matters but the structure should remain simple for frontend consumption.
5. Converting JSON Back to XML
Reversing the conversion requires the same convention the original XML-to-JSON walk used. The BadgerFish convention round-trips a nested JSON object back to the same XML document because each attribute lives in its own key namespace and the textual content stays distinct from child elements. The Parker convention cannot round-trip because attributes were discarded, so the reverse walk has nothing to work with. The GData convention round-trips but reconstructs attributes out of nested namespace keys, which requires the consumer of the JSON to know that convention is in effect.
When your pipeline spans a producer that emits XML and a consumer that wants JSON, document the chosen convention at the API layer and pick BadgerFish or GData rather than Parker so that downstream consumers can convert back if necessary.
Conclusion
XML-to-JSON conversion is never free, but choosing the right convention upfront makes the round-trip clean enough for everyday data flow. ToolWise Free Online XML to JSON Converter offers all three conventions, supports the reverse direction, and runs entirely in your browser without uploading the document. Paste the XML, pick the convention, copy the JSON.