Engineering Guides5 min readUpdated: 2026-11-24

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.

Quick Answer

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.

Convert XML with attributes to JSON →

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 ConstructJSON Representation (@_ prefix)JSON -> XML ResultDataTo 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 XMLFormatted JSON object2-space indented or compact XMLformatXml, indent

Convert JSON back to valid XML →

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"
  }
}

Inspect JSON tree & sort keys →

Tools used in this guide

Data Convert →

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