What is an XML to JSON converter?
An XML to JSON converter transforms XML data into equivalent JSON. Use this tool when you need to inspect SOAP responses in JSON-based debugging tools, migrate configuration files from XML to JSON, consume XML APIs in a codebase that works with JSON, or compare XML and JSON representations side by side. The converter preserves element names, text content, and (optionally) attributes, mapping the tree structure of XML into nested JSON objects.
How to use the XML to JSON converter
- Paste XML: Add your XML into the input box. The input must contain exactly one root element.
- Choose attribute handling: Enable "Keep attributes" if your XML uses attributes like
id="123"that you want preserved. When enabled, attributes appear under an@attributeskey in the output. - Copy JSON: Click the copy button to grab the JSON output for your debugger, test file, or API tooling.
Why use this XML to JSON tool?
- Bridge legacy and modern systems: Many enterprise APIs still return XML (SOAP, RSS, Atom). Converting to JSON lets you work with the data in modern JavaScript, Python, or Go tooling.
- Easier debugging: JSON is natively supported in browser dev tools, Postman, and VS Code. Converting XML to JSON lets you use familiar tree-view inspectors.
- Config migration: Moving from XML-based configuration (Spring, Maven, .NET
web.config) to JSON-based configuration (Node.js, Next.js, Vite) starts with a structural conversion. - Private conversion: Parsing happens locally in your browser. No XML payloads are sent to a server.
Use case 1: Debug a SOAP API response
Copy the XML response body from your API client, paste it into the converter, and inspect the JSON output in your browser console or a JSON formatter. This is faster than manually reading nested XML tags.
Use case 2: Migrate Maven POM settings to JSON
Extract dependency declarations from a pom.xml, convert to JSON, and restructure them for a package.json or a custom build manifest. The structural conversion saves time compared to manual rewriting.
Use case 3: Process RSS feed data in JavaScript
RSS and Atom feeds are XML. Convert a feed snapshot to JSON so you can parse it with JSON.parse() and loop through entries with standard array methods.
Use case 4: Compare XML and JSON representations
Side-by-side comparison helps when you are writing a parser or serializer. Convert the XML, format both documents, and diff them to verify your mapping logic.
How the conversion works
The converter parses the XML string into a DOM tree, then walks the tree recursively, mapping each element to a JSON object:
- Element nodes become JSON object keys. The key is the tag name.
- Text content becomes the value. If an element has only text content and no children, it maps to a string value.
- Child elements become nested objects. If an element has multiple children with the same tag name, they are grouped into a JSON array.
- Attributes (when enabled) are placed in an
@attributessub-object to keep them separate from child elements. - Namespaces are preserved in the tag names where present (e.g.,
soap:Envelope).
This approach follows the convention used by popular XML-to-JSON libraries like xml2js and fast-xml-parser, so the output structure should be familiar to most developers.
Examples
Example 1: XML with attributes
Input:
<person id="123">
<name>Alice</name>
<age>30</age>
</person>
Output (attributes enabled):
{
"person": {
"@attributes": { "id": "123" },
"name": "Alice",
"age": "30"
}
}
Example 2: Repeated child elements
Input:
<catalog>
<item>Widget A</item>
<item>Widget B</item>
<item>Widget C</item>
</catalog>
Output:
{
"catalog": {
"item": ["Widget A", "Widget B", "Widget C"]
}
}
Repeated elements with the same tag are automatically converted to a JSON array.
Common errors
"Invalid XML"
This error means one of the following:
- A closing tag is missing (e.g.,
<name>Alicewithout</name>). - The document contains invalid characters (unescaped
&,<, or>inside text). - There are multiple root elements. XML requires exactly one root.
Fix the input first with XML formatter, which will highlight the exact error location.
All values are strings
XML has no native type system. Numbers, booleans, and dates are all stored as text. The converter outputs everything as JSON strings to preserve fidelity. If you need typed values, parse them in your code after conversion (e.g., parseInt(json.person.age)).
Attributes are missing from the output
Make sure "Keep attributes" is turned on. When it is off, attributes are silently dropped to produce a cleaner output.
Namespace prefixes clutter the keys
SOAP envelopes and XML Schema documents use namespace prefixes like soap:, xs:, and xsi:. These prefixes are preserved in the JSON keys. If you want to strip them, post-process the JSON with a simple find-and-replace or regex.
Tips and proven approaches
- Validate and format XML first with XML formatter to catch syntax errors before converting.
- Format the JSON output with JSON formatter for readability when debugging.
- Keep attributes enabled for SOAP responses and configuration files where attributes carry essential data (IDs, types, namespaces).
- Turn attributes off for simple data-only XML (like RSS feeds or export files) to get a cleaner, flatter JSON structure.
- Chain conversions: Convert XML to JSON, then JSON to YAML with JSON to YAML for config files that need to end up in YAML format.
Related tools
- Clean and validate input with XML formatter.
- Pretty-print the output with JSON formatter.
- Convert between config formats with YAML to JSON and JSON to YAML.
- Minify JSON output with JSON minifier.
Privacy and security
This conversion runs locally in your browser. Your XML data is not uploaded to any server. All parsing and transformation happens on your device, so you can safely convert API responses, configuration files, and data exports containing sensitive information.