XML ↔ JSON Converter
Convert XML to JSON and JSON to XML with auto-detection, download, and advanced formatting controls.
Advanced — 2-space indent · Root: root · Prefix: @_ · Text: #text · Keep namespaces
What is XML ↔ JSON Converter?
XML ↔ JSON Converter transforms XML documents into JSON objects and JSON back into XML. XML is common in SOAP APIs, config files, and legacy systems; JSON dominates modern APIs and web apps. Converting between them bridges old and new systems, simplifies API integration, and makes config files easier to work with. The tool handles nested elements, attributes, and text content—preserving structure in both directions.
Real-world use cases include converting SOAP or REST API XML responses to JSON for frontend consumption, transforming config files between formats, debugging XML by inspecting the JSON structure, and preparing JSON for systems that expect XML. Attributes are stored under a configurable prefix (default @_attributes); text nodes use a configurable key (default #text). All conversion runs in your browser—no upload, no server.
How to Use XML ↔ JSON Converter
- Switch to XML → JSON or JSON → XML. Paste your data—the tool auto-detects format.
- Click Convert to transform. The output shows the converted structure with indentation.
- Open Advanced to set JSON indentation (2 or 4 spaces, or tab), and the root element name for JSON→XML.
- Adjust attribute prefix and text node key if your XML uses different conventions.
- Enable Strip namespaces to remove XML namespace prefixes from element names.
- Click Save to download as
.jsonor.xml. Use Copy to paste elsewhere.
Tips & Best Practices
For JSON→XML, set the root element name when converting a plain object—default is root. Attributes in JSON use the prefix (e.g. @_attributes) so they round-trip correctly. Invalid XML triggers a parser error—ensure proper encoding, closing tags, and escaped special characters. Press Ctrl+Enter to convert and Ctrl+Shift+C to copy. For CSV or YAML, use our CSV JSON Converter or JSON YAML Converter.
When to Use This Tool
Use XML ↔ JSON when integrating with SOAP/REST APIs, converting config files, debugging XML structures, or bridging legacy and modern systems. Pair with CSV JSON Converter for tabular data, or JSON YAML Converter for Docker/Kubernetes configs. The JSON formatter helps validate JSON output. All conversion runs client-side—your data stays private.
Frequently Asked Questions
Can I convert SOAP or REST API XML to JSON?
Yes. Paste XML in the input and click XML → JSON. The tool parses attributes, nested elements, and text content into a JSON structure. Ideal for API responses and config files.
Can I convert JSON back to XML?
Yes. Paste JSON in the input and click JSON → XML. The tool converts the JSON structure back to XML output.
How do I set the root element for JSON → XML?
Use the 'JSON → XML root element' field. When converting a plain JSON object (not wrapped), this becomes the root tag. Default is 'root'.
Does it preserve XML attributes?
Yes. Attributes are mapped to @_attributes (or your configured prefix) in the JSON output. When converting JSON → XML, they are written back as element attributes.
What XML features are supported?
The converter supports elements, attributes, nested structures, and text content. Namespaces can be stripped optionally.
Can I convert CSV or YAML instead?
For CSV ↔ JSON, use our CSV JSON Converter. For JSON ↔ YAML (Docker, K8s configs), use our JSON YAML Converter. All run in your browser.
What if my XML is invalid?
The browser's DOMParser validates XML. Invalid XML will show an error with location info. Ensure proper encoding, closing tags, and escaped special characters.