Skip to content
TypeParser
All tools

XML to JSON

Convert XML to JSON.

beats codebeautify.org edge: Attribute prefix + configurable text key
XML
paste XML
Guide

About XML to JSON

Convert XML to JSON via the browser's DOMParser. Pick how attributes (<code>@key</code> by default) and text content (<code>#text</code> by default) appear in the output. Round-trips cleanly back to XML in most cases. Useful for processing legacy feeds, SOAP responses, and exported configs in JSON-native code.

When you need this

Modern services speak JSON. Legacy systems — SOAP services, RSS feeds, Atom feeds, OOXML, sitemaps, SVG metadata, Android resources — speak XML. Converting at the boundary is the cleanest way to keep the legacy data flowing into modern code without scattering XML parsing across your codebase.

What survives the conversion

  • Element nesting → object nesting
  • Repeated elements → JSON arrays
  • Attributes → @-prefixed keys
  • Text content → #text keys (or value-only when there is no mixed content)
  • Namespaces → preserved in element names

What loses fidelity

  • Element order in mixed content
  • Comments
  • Processing instructions
  • DOCTYPE
  • Whitespace exactly as authored

For round-trippable data XML (RSS, Atom, configs), this is fine. For document XML (XHTML, DocBook), expect to lose layout.

Common workflows

Consume an RSS feed in JS. Fetch the XML, convert to JSON, iterate items array, render. No XML parsing in your application code.

Bridge a SOAP service to a REST front-end. SOAP responses are XML; convert at the gateway, hand JSON to the rest of the system.

Audit a sitemap. XML sitemaps convert to a JSON array of { loc, lastmod, priority } you can grep, filter, count.

Process Android resources. strings.xml, colors.xml convert to JSON for a build script that wants typed access.

Round-trip caveat

If you plan to convert back via JSON to XML (not yet available — use a library), preserve the attribute/text conventions. The converter assumes the same prefixes both directions; mismatching produces garbage.

Frequently asked questions

How are attributes mapped?
By default, attributes become keys prefixed with @ — so <item id="1"> becomes {"@id": "1"}. Toggle the prefix or pick "merge" to put attributes into the object directly (loses round-trip capability).
What about mixed content?
<p>Hello <b>world</b></p> keeps text and elements separate via {"#text": "Hello ", "b": "world"}. Imperfect for complex documents but adequate for data-XML.
Are namespaces preserved?
Yes. xmlns:foo="..." declarations stay; element names retain their prefix.
Can I round-trip back?
Mostly. With the default attribute and text key conventions and a single child per element, JSON → XML reconstructs identically. Mixed content and order-sensitive XML lose structure.
How does it differ from yaml conversion?
YAML-to-JSON is a 1-to-1 structural mapping; XML-to-JSON is lossy because XML carries info JSON does not have (attribute order, mixed content, comment positions).
Does it validate the XML first?
Yes — DOMParser raises a parse error if the input is malformed. You see the line and column before any conversion happens.

Related tools

Last updated: 2025-01-15