XML ↔ JSON Converter

Convert XML to JSON or JSON to XML instantly. Handles attributes, text content, and repeated elements. 100% client-side.

XML Input
JSON Output
Paste XML or JSON above to convert.

How to Use the XML to JSON Converter

  1. Choose a direction — "XML to JSON" or "JSON to XML" using the chips above the input.
  2. Paste your data into the input area on the left.
  3. View the converted output on the right, updating as you type.
  4. Copy or download the result as a .json or .xml file.

Conversion Conventions

Converting between XML and JSON requires a mapping convention because the two formats have fundamentally different concepts. This tool uses the widely adopted BadgerFish-inspired convention:

  • XML attributes become JSON properties prefixed with @ (e.g., <el id="1"> becomes { "@id": "1" })
  • Mixed content (element with both attributes and text) uses #text for the text portion
  • Repeated sibling elements are grouped into a JSON array
  • Text-only elements with no attributes become plain string values
  • Nested elements become nested JSON objects

XML vs. JSON: Key Differences

XML and JSON serve similar purposes but have different strengths. XML supports attributes (metadata about elements), mixed content (text and child elements in the same element), namespaces (XML Schema, SOAP), comments, processing instructions, and CDATA sections. JSON is simpler, lighter, and maps directly to programming language data structures. Most modern REST APIs use JSON, while SOAP APIs, RSS/Atom feeds, SVG graphics, Microsoft Office files (DOCX, XLSX), and many enterprise system integrations use XML. Converting between them is common when migrating legacy systems or working with multi-format APIs.

Common Use Cases

  • SOAP to REST migration — Convert SOAP XML responses to JSON for use with modern REST clients
  • RSS/Atom feed parsing — Convert feed XML to JSON for JavaScript processing
  • Configuration files — Convert Maven/Gradle XML configs to JSON format for tooling
  • API format bridging — Some APIs accept both formats; convert before submission
  • Data transformation pipelines — Convert XML exports from legacy systems to JSON for modern databases

Limitations

The conversion cannot perfectly preserve all XML features. XML namespaces, processing instructions (<?xml ... ?>), CDATA sections, and XML comments are not preserved in the JSON output. The root element name is preserved as the top-level key in the JSON object. When converting JSON back to XML, properties with @ prefix become attributes, and arrays generate repeated elements with the same tag name. The root element is named "root" by default if the JSON starts with an object.

Working with SOAP XML

SOAP XML responses typically include namespace prefixes (e.g., <ns1:Body>) and deeply nested envelope structures. The converter handles namespaced elements by preserving the prefix as part of the property name in JSON. For complex SOAP responses, you may need to navigate through the envelope structure in the resulting JSON. For production SOAP integration, consider using dedicated SOAP client libraries that handle namespace resolution automatically.

Frequently Asked Questions

XML element attributes are converted to JSON properties prefixed with @ (e.g., an attribute 'id' becomes '@id'). This convention preserves attribute data while making it clear in the JSON output which properties came from XML attributes versus child elements.
When the same element name appears multiple times within a parent element, they are automatically grouped into a JSON array. For example, multiple <item> elements under <items> will be converted to an items array in the JSON output.
No. This XML/JSON converter runs 100% in your browser using the built-in DOMParser API for XML parsing. Your data never leaves your machine. There is no server-side processing, no logging, and no data collection.
#text represents the text content of an XML element that also has attributes or child elements. For example, <price currency="USD">9.99</price> becomes { "@currency": "USD", "#text": "9.99" }. If an element has only text and no attributes or children, it is represented as a plain string value.
Yes. Switch to "JSON to XML" mode and paste your JSON. The converter generates well-formed XML with proper indentation. Object keys become element names, arrays become repeated elements, and properties prefixed with @ are converted back to XML attributes.