Two-way XML ↔ JSON; preserves attributes, text nodes, namespaces.

Switch tool
XML0 chars · 0 lines
JSON0 chars · 0 lines

How to use

Purpose

Dedicated XML and JSON bidirectional converter handling elements, attributes (@attr prefix), text nodes (#text), CDATA, namespaces, multiple same-name children auto-converting to arrays. XML→JSON supports compact mode (attributes on object root) or safe mode (attributes in @ prefix sub-object). JSON→XML supports custom root element, indent control, attribute/element strategy. Common in SOAP/REST API conversion, legacy XML config upgrades to JSON, API doc generation. All conversion runs locally.

Steps

  1. Paste XML or JSON on the left; auto-detected
  2. Right pane shows the converted result
  3. XML → JSON mode: compact (attributes on object) or safe (attributes in @attributes sub-object)
  4. XML → JSON: multiple same-name children become a JSON array
  5. CDATA content preserved as string value by default
  6. JSON → XML: specify the root element name (default "root")
  7. JSON convention: keys starting with @ become XML attributes (@id → id="...")
  8. Preserves namespace prefixes (xmlns:prefix)

FAQ

How are attributes distinguished from elements after XML → JSON?
Safe mode: attributes go into @attributes or _attr sub-object, no naming conflict with elements. Compact mode: attributes sit on the parent object, requires XML has no same-name attribute and child. Use safe mode for clarity (item._attr.id vs item.id).
Multiple same-name children in XML → JSON?
e.g. `<list><item>a</item><item>b</item></list>` → `{"list":{"item":["a","b"]}}`. A single item becomes a string ("a") not a single-element array. "Force array" mode makes all items arrays (no if-Array-else-String branching needed in calling code).
How is XML CDATA converted to JSON?
CDATA content converts to a string value (containing < > & literally). "Preserve CDATA marker" mode wraps as `{"#cdata": "..."}` for round-trip back to XML CDATA.
What is the root element when converting JSON to XML?
JSON has no root concept; XML must have one. Tool defaults to "root"; rename to "Response", "Data", etc. If JSON is an array `[1,2,3]`, two layers of nesting are needed (root → item × 3).
Will namespaces (xmlns) be lost in conversion?
No. XML → JSON preserves namespace declarations as @xmlns attributes; prefixes become part of the key (soap:Envelope → "soap:Envelope"). JSON → XML: manually include @xmlns to generate namespace declarations.

Use cases

  • SOAP API to REST: legacy SOAP returns XML; frontend processes in JSON
  • Legacy config upgrade: batch convert XML configs to JSON
  • API doc generation: OpenAPI/Swagger converts XML schema to JSON schema
  • Crawler XML data: scraped XML converted to JSON for database storage
  • SDK dual-protocol support: XML and JSON clients both supported via conversion

Use cases

SOAP-REST bridging, legacy config upgrades, API doc conversion, crawler data, SDK dual-protocol. Backend, data engineering. Attribute strategy, force-array, CDATA preservation, namespace handling are the differentiators.