XML ↔ JSON Converter
Convert XML to JSON and JSON to XML instantly with this free online tool. Handles attributes, arrays, nested elements, and custom indentation.
Indentation:
XML to JSON
Input XML
JSON Result
Related Tools
About XML ↔ JSON Converter
How It Works
- Converts XML to JSON by mapping elements, attributes, and text nodes
- Converts JSON back to valid XML with proper nesting and attribute handling
- Repeated XML child elements are automatically grouped into JSON arrays
- XML attributes are stored under a special @attributes key in JSON
- Supports custom indentation for both JSON and XML output
- Provides instant preview and one-click copy for converted output
Common Use Cases
- Transforming legacy XML APIs to modern JSON format
- Converting XML configuration files for use in JavaScript projects
- Migrating data pipelines between XML and JSON-based systems
- Debugging and inspecting XML response payloads as readable JSON
- Preparing data for import into databases or REST APIs
Frequently Asked Questions
What is the difference between XML and JSON?
XML (Extensible Markup Language) is a tag-based markup format with support for attributes, namespaces, comments, and metadata. JSON (JavaScript Object Notation) is a lightweight key-value format that is easier to parse in modern programming languages and APIs. XML is often used in legacy enterprise systems, while JSON dominates modern web APIs.
How are XML attributes handled in JSON output?
XML attributes are mapped to a special "@attributes" key inside the corresponding JSON object. For example, <person id="1"> becomes { "person": { "@attributes": { "id": "1" } } }. This preserves all attribute data during conversion.
How are repeated XML elements converted to JSON?
Sibling XML elements with the same tag name are automatically grouped into a JSON array. For instance, multiple <item> elements inside a parent become an array under the "item" key in JSON.
What JSON structure is required for JSON to XML conversion?
The root JSON value must be an object with a single key that becomes the root XML element. If your JSON has multiple root-level keys, the tool wraps them inside a <root> element automatically. Nested objects map to child elements, and arrays produce repeated sibling elements.
Are XML comments preserved in the JSON output?
No, XML comments (<!-- ... -->) are not preserved during conversion to JSON because JSON has no native comment syntax. Likewise, XML processing instructions are ignored.
Can I customize the indentation of the output?
Yes. Use the indentation selector at the top of the tool to choose 1, 2, or 4 spaces. This setting affects both the JSON and XML output.
Does the conversion happen automatically?
Yes. Both converters update their output in real time as you type or paste input. You do not need to click a button — the result appears instantly.
What happens if my XML or JSON is invalid?
The tool displays a clear error message in the output area showing exactly what went wrong. Fix the syntax issue in the input and the output will update automatically.
Is there a file size limit?
There is no enforced size limit, but very large documents may slow down the browser because all processing happens client-side. The tool works best with typical configuration files and API payloads.
Does this tool send my data to a server?
No. All XML and JSON processing is done entirely in your browser using JavaScript. Your data never leaves your device, ensuring full privacy.
How do I copy the converted result?
Click the "Copy to Clipboard" button that appears below the output area after a successful conversion. The entire converted text will be copied and ready to paste elsewhere.
Can I convert XML namespaces to JSON?
Namespace prefixes are preserved as part of element names (e.g., ns:element becomes the key "ns:element" in JSON). Namespace declarations (xmlns attributes) are included in the @attributes object.