XML Attributes to JSON: Lossless @_ Prefix & Round-Trip Guide
Convert XML, SVG, RSS, SOAP, and Maven pom.xml to typed JSON with @_ attribute preservation, XXE-safe pure-JS Web Worker parsing, and clean JSON to XML.
Follow this XML attributes to JSON round-trip guide to convert XML with attributes to JSON cleanly using DataTo's @_ attribute prefix convention, then map those @_ keys back into XML attributes in JSON to XML. Because fast-xml-parser executes purely in a sandboxed browser Web Worker with zero filesystem or network entity loading, it acts as a safe browser XML parser with no XXE risk.
Why naive converters corrupt XML attributes and text nodes
Unlike JSON objects, XML elements carry metadata in two places: element attributes (such as id="INV-402" or currency="USD") and child elements or text values. Naive XML-to-JSON scripts drop attributes completely or flatten them inconsistently so converting back to XML loses critical fields.
Whether you are transforming enterprise SOAP invoices, RSS/Atom feeds, SVG icons, Android manifests, or Maven pom.xml files, using a predictable JSON-to-XML attribute prefix keeps structure intact across both directions.
The @_ attribute prefix mapping table & round-trip example
DataTo XML to JSON and JSON to XML configure fast-xml-parser with a shared attributePrefix (defaulting to @_), automatic numeric/boolean coercion (parseTagValue and parseAttributeValue), and configurable XML root tags.
<invoice id="INV-402" currency="USD">
<customer tier="enterprise">Northwind Labs</customer>
<total taxIncluded="false">1250.00</total>
</invoice>| XML Construct | JSON Representation (@_ prefix) | JSON -> XML Result | DataTo Option |
|---|---|---|---|
| <order id="104" paid="true"> | {"order": {"@_id": 104, "@_paid": true}} | <order id="104" paid="true"> | preserveAttributes, attributePrefix |
| <total currency="USD">149.95</total> | {"total": {"#text": 149.95, "@_currency": "USD"}} | <total currency="USD">149.95</total> | attributePrefix (default @_) |
| Top-level JSON array [...] | [{"sku": "A1"}, {"sku": "B2"}] | <root><item>...</item></root> | rootTagName (default root) |
| Pretty-printed vs. compact XML | Formatted JSON object | 2-space indented or compact XML | formatXml, indent |
XXE-safe pure-JS Web Worker parsing & batch ZIP exports
Server-side XML converters backed by native C or Java XML libraries can expose XML External Entity (XXE) vulnerabilities when parsing untrusted payloads. DataTo runs XMLValidator.validate() and pure-JS fast-xml-parser inside an isolated Web Worker in browser RAM with zero filesystem access or external entity fetching.
When working across multiple .xml, .svg, or .rss files, select a batch of documents locally to convert all files at once and download a single ZIP archive, or inspect the resulting JSON structure in JSON Formatter.
{
"invoice": {
"customer": {
"#text": "Northwind Labs",
"@_tier": "enterprise"
},
"total": {
"#text": 1250,
"@_taxIncluded": false
},
"@_id": "INV-402",
"@_currency": "USD"
}
}Tools used in this guide
Data Convert →Parse XML 1.0 documents with configurable @_ attribute preservation and typed primitives via pure-JS fast-xml-parser.
Serialize JSON objects and @_ attributes into clean, well-formed XML 1.0 with configurable root wrapper tags locally.
Pretty-print, minify, sort keys, auto-repair trailing commas, and browse collapsible JSON trees in browser RAM.
JSON to CSVFlatten nested JSON arrays into RFC-4180 CSV with delimiter selection and default UTF-8 BOM for Microsoft Excel.
JSON to TOONShrink JSON arrays into Token-Oriented Object Notation (TOON) to cut GPT-4o and Claude prompt tokens up to 60%.
Related formats
Related Comparisons
Frequently asked questions
Can I change the @_ attribute prefix to $ or another character sequence?
Yes. Both XML to JSON and JSON to XML expose an XML attribute prefix text option so you can use @_, $, or any custom prefix consistently across round-trips.
How does DataTo handle syntax errors like mismatched closing tags?
XMLValidator.validate() checks well-formedness first and surfaces the exact line number, column number, and parser diagnostic before conversion.
Can I convert SVG or RSS documents as well as standard XML?
Yes. XML to JSON accepts .xml, .svg, and .rss files directly in browser RAM and supports multi-file batch conversion to ZIP.
Authoritative References
More engineering guides
Count exact o200k_base and cl100k_base BPE tokens offline, visualize token boundary segments, prune null JSON fields, and cut prompt API costs locally.
TOML vs. YAML vs. JSON: Picking the Best Configuration FormatCompare TOML 1.0, YAML 1.2, and JSON for Kubernetes, CI pipelines, Rust Cargo.toml, Python pyproject.toml, and API configs—and convert locally.
JSON vs. TOON vs. YAML: LLM BPE Token Benchmarks in 2026Compare GPT-4o o200k_base BPE token counts across formatted JSON, minified JSON, YAML, CSV, and TOON—plus how TOON cuts prompt array tokens 40%–60%.
Structural JSON Diff & Primary-Key CSV Diff for Data ValidationCompare API payloads and database table exports cleanly using key-order-normalized structural JSON diff and primary-key-aligned CSV diff locally.