Guides
XML to JSON: Preserving Attributes, CDATA & RSS Feeds
Convert XML, RSS, and SVG files to JSON in browser RAM while preserving @_ attributes, CDATA text, numeric types, and round-trip XML structure.
Quick Answer: To convert XML, RSS, or SVG documents into JSON without dropping metadata, keep Ignore Attributes turned off and use the @_ attribute prefix. TxtTo validates XML line and column errors locally, unwraps CDATA blocks into clean JSON strings, coerces numbers and booleans when Parse Tag Value is enabled, and round-trips @_ attributes back into valid XML.
Why XML attributes, text nodes, and CDATA clash with JSON
Unlike JSON objects that store flat key-value pairs, XML elements mix tag attributes, inner character data, repeated sibling nodes, and CDATA blocks that hold unescaped HTML or code.
Naive converters either throw away XML attributes completely or flatten repeated RSS item tags inconsistently, breaking downstream TypeScript types and API parsers.
- Element attributes like id="bk101" live inside opening tags rather than child keys.
- Repeated sibling elements such as RSS item entries must map cleanly into JSON arrays.
- CDATA sections embed markup or scripts containing < and & without entity escaping.
<catalog currency="USD">
<book id="bk101">
<title><![CDATA[Browser <em>XML</em> Guide]]></title>
<price>39.00</price>
</book>
</catalog>Controlling ignoreAttributes, attributePrefix (@_), and parseTagValue
TxtTo runs fast-xml-parser entirely inside browser RAM so you can tune attribute and type behavior live without sending proprietary feeds or SOAP payloads over the network.
Leave ignoreAttributes disabled and keep attributePrefix at @_ so attribute values stay distinguishable from child tags. Disable parseTagValue whenever leading zeros in postal codes, invoice numbers, or SKU identifiers must stay strings instead of numbers.
{
"catalog": {
"@_currency": "USD",
"book": {
"@_id": "bk101",
"title": "Browser <em>XML</em> Guide",
"price": 39
}
}
}Validating malformed XML and inspecting RSS or SVG trees
Before parsing, XMLValidator checks well-formedness locally and pinpoints unclosed tags or mismatched attributes by exact line and column number. That catches broken RSS exports or truncated SVG markup before data enters your pipeline.
Once converted, open the output in JSON Formatter to inspect deep hierarchies in Tree View, sort keys alphabetically, or repair trailing commas after manual edits.
Inspect & format converted JSON trees
| Option | Default | Behavior | When to Change |
|---|---|---|---|
| ignoreAttributes | false | Keeps all XML tag attributes in JSON | Enable only if attributes are noisy layout hints |
| attributePrefix | @_ | Prepends @_ to attribute keys | Change if downstream consumer expects _ or $ |
| parseTagValue | true | Coerces numeric and boolean strings | Disable to preserve leading zeros like 00412 |
| indent | 2 | Formats JSON with 2-space indentation | Set to 0 for compact single-line output |
Round-tripping JSON back to XML with rootName & includeDeclaration
Because valid XML requires a single outer root element, JSON to XML wraps top-level arrays under <item> tags inside your chosen rootName (defaulting to root) and prepends <?xml version="1.0" encoding="UTF-8"?> when includeDeclaration is active.
Any JSON key carrying the @_ prefix serializes straight back into an XML attribute, and you can compare edited round-trips locally with Diff Checker.
References
Frequently asked questions
How are XML CDATA blocks handled when converting to JSON?
CDATA wrappers are unwrapped into clean string values in JSON without double-escaping HTML tags or ampersands.
How do I preserve leading zeros like ZIP codes or SKU IDs in XML to JSON?
Turn off Parse Tag Value so numeric-looking text such as 02139 remains a JSON string rather than converting to 2139.
Can JSON to XML recreate XML attributes from converted JSON?
Yes. Any property starting with @_ in your JSON object is automatically written back as an attribute on its parent XML element.
Related formats
Related Comparisons
Related Guides
- Offline JWT Decoding, Base64URL & Semantic JSON DiffingInspect JWT headers and claims, encode Base64URL without padding, run key-order-agnostic semantic JSON diffs, and scrub Bearer tokens offline.
- Why Server-Side Paste Tools Leak Secrets — Zero-Upload ArchitectureLearn why pasting .env files, JWTs, customer CSVs, or contracts into cloud converters leaks data—and how to verify 0 bytes uploaded locally.
- Generating TypeScript, Zod & Pydantic v2 Schemas from JSONTurn API JSON samples into strict TypeScript interfaces, runtime Zod validators, and Python Pydantic v2 BaseModels with optional & alias inference.