Formatter Validator Minifier Escape / Unescape JSON ↔ String JSON ↔ YAML JSON → CSV NDJSON / JSON Lines JSON → Types JSON ↔ XML JSON Diff JSON Patch Canonicalize (RFC 8785) Schema Validator Schema Generator JSONPath Tester JWT Decoder JSON Errors Schemas More Tools
Bi-directional · Preserves attributes and structure

JSON ↔ XML Converter

Convert JSON to XML or XML to JSON while preserving attributes, text content, and nesting. Essential when working with legacy SOAP APIs, RSS/Atom feeds, or migrating data between modern and legacy systems.

Input JSON
Output XML
Converted output will appear here

When you need JSON ↔ XML conversion

XML preceded JSON as the dominant data-interchange format on the web, and despite JSON's takeover for new APIs, XML remains everywhere in legacy systems. Anyone working at the boundary between modern and legacy stacks needs a way to convert between the two.

Common reasons to convert:

  • SOAP web services still power many enterprise systems (banking, government, healthcare). SOAP envelopes are XML. To integrate with a modern app that prefers JSON, you convert at the boundary.
  • RSS and Atom feeds are XML by spec. To process them with JSON-based tools (most modern data pipelines), convert first.
  • Office Open XML formats (.docx, .xlsx) use XML internally. Tools that introspect Word or Excel files often work with the XML directly.
  • Configuration files in older Java/.NET projects often use XML. Migrating to modern JSON-based tooling means a one-time conversion.
  • EDI and HL7 healthcare data, banking ISO 20022 messages, and other industry standards still use XML. JSON conversion makes them easier to process in modern stacks.

How attributes and text are preserved

XML and JSON have different data models. XML elements can have both attributes (metadata on the element) and text content, plus child elements. JSON only has keys and values. To preserve information, our converter uses a convention:

  • XML attributes become JSON keys prefixed with @. <book id="123"> becomes {"@id": "123"}.
  • Element text content (when an element has both attributes and text) becomes a key called #text.
  • Pure text elements (no attributes, no children) become a simple string value.
  • Repeated elements become arrays in JSON.

This convention is the de facto standard used by libraries like xml-js, fast-xml-parser, and Underscore's XML helpers. It survives round-trips cleanly: XML → JSON → XML produces a structurally equivalent document.

FAQ — Json To Xml

How are XML attributes converted to JSON?
Attributes become JSON keys prefixed with @. So <user id="42" role="admin">Alice</user> becomes {"user": {"@id": "42", "@role": "admin", "#text": "Alice"}}. This is the de facto convention used by most XML-to-JSON libraries.
Are XML namespaces supported?
Basic namespace prefixes are preserved as part of element names (so <ns:tag> becomes a JSON key "ns:tag"). Full namespace resolution with xmlns declarations is not performed — the converter treats prefixes as opaque strings.
What happens to CDATA sections?
CDATA content is preserved as plain text in the JSON. When converting JSON back to XML, special characters in the text are properly escaped — but they won't be re-wrapped in CDATA sections unless you explicitly request it.
Does this handle SOAP envelopes?
Yes, structurally. SOAP's envelope/body/header nesting converts cleanly. The namespace declarations on the envelope are preserved as @xmlns:soap attributes. You may need to manipulate the resulting JSON to feed it into a modern API.
Can I convert XHTML or HTML?
XHTML (which is well-formed XML) converts fine. Plain HTML (which often isn't well-formed — unclosed tags, missing quotes) will fail XML parsing. For HTML-to-JSON, use a dedicated HTML parser like Cheerio or BeautifulSoup.
How are XML comments handled?
XML comments (<!-- ... -->) are stripped during conversion to JSON since JSON has no comment representation. Going back from JSON to XML, comments aren't reconstructed.
What about XML processing instructions and DOCTYPE?
The XML declaration (<?xml version="1.0"?>) is preserved on output but not represented in the JSON. DOCTYPE declarations are stripped — JSON has no equivalent.
Can I convert RSS or Atom feeds to JSON?
Yes, both convert cleanly. The result is structurally close to what dedicated RSS-to-JSON parsers produce, though the key names follow the @/# convention rather than the more opinionated keys some libraries use.
Will the JSON validate against an XML Schema?
Not directly — XML Schema (XSD) is XML-specific. But you can write a JSON Schema that mirrors your XSD's constraints, then validate the converted JSON against it using our JSON Schema Validator.
How big a document can I convert?
Up to about 10 MB on most browsers. XML parsing is slower than JSON parsing because the DOM tree is larger in memory. For larger documents, use a command-line tool like xq (XML + jq).

Where to go next