This WSDL to JSON tool is designed to solve that specific friction point. It parses the strict hierarchy of your WSDL code—including definitions, messages, port types, and bindings—and intelligently maps them into a JavaScript Object Notation (JSON) format.
Your JSON output will appear here...
Copied to clipboard!
`;
copyBtn.disabled = true;
downloadBtn.disabled = true;
}
/**
* Shows a toast message.
*/
function showToast(message) {
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 2000); // Show for 2 seconds
}
/**
* Copies the output text to the clipboard.
*/
function copyOutput() {
const textToCopy = output.textContent;
const tempTextarea = document.createElement('textarea');
tempTextarea.value = textToCopy;
document.body.appendChild(tempTextarea);
tempTextarea.select();
try {
document.execCommand('copy');
showToast('Copied to clipboard!');
} catch (err) {
showToast('Failed to copy!');
}
document.body.removeChild(tempTextarea);
}
/**
* Downloads the output text as a JSON file.
*/
function downloadOutput() {
const textToDownload = output.textContent;
const blob = new Blob([textToDownload], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'converted.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
/**
* Recursively converts an XML DOM node to a JS object.
*/
function xmlNodeToJS(node) {
let data = {};
// 1. Handle attributes
if (node.nodeType === 1 && node.attributes.length > 0) {
data["@attributes"] = {};
for (let i = 0; i < node.attributes.length; i++) {
const attr = node.attributes[i];
data["@attributes"][attr.nodeName] = attr.nodeValue;
}
}
// 2. Handle children
if (node.hasChildNodes()) {
// Special case: single text node child
if (node.childNodes.length === 1 && node.childNodes[0].nodeType === 3) {
const text = node.childNodes[0].nodeValue.trim();
if (text) {
// If node has attributes, return object with text
if (Object.keys(data).length > 0) {
data["#text"] = text;
return data;
}
// If no attributes, just return the text
return text;
}
}
// Handle multiple children
for (let i = 0; i < node.childNodes.length; i++) {
const child = node.childNodes[i];
let childData;
if (child.nodeType === 1) { // Element node
childData = xmlNodeToJS(child);
} else if (child.nodeType === 3) { // Text node
const text = child.nodeValue.trim();
if (text) {
// This handles text nodes mixed with element nodes
childData = text;
if (data["#text"] === undefined) {
data["#text"] = childData;
} else {
if (!Array.isArray(data["#text"])) {
data["#text"] = [data["#text"]];
}
data["#text"].push(childData);
}
}
continue; // Continue to next child
} else {
continue; // Skip comments, etc.
}
// Add child data to parent data
const nodeName = child.nodeName;
if (data[nodeName] === undefined) {
data[nodeName] = childData;
} else {
// Already exists, make it an array
if (!Array.isArray(data[nodeName])) {
data[nodeName] = [data[nodeName]];
}
data[nodeName].push(childData);
}
}
}
return data;
}
/**
* Main function to parse XML and convert to JSON.
*/
function convertXMLtoJSON() {
const xmlString = xmlInput.value.trim();
if (!xmlString) {
displayError('Input is empty. Please paste your WSDL code.');
return;
}
try {
// 1. Validate the XML
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, "application/xml");
const errorNode = xmlDoc.querySelector("parsererror");
if (errorNode) {
const errorMsg = errorNode.innerText || errorNode.textContent;
displayError(`Error parsing XML: ${errorMsg}`);
return;
}
// 2. Convert to JS object
const root = xmlDoc.documentElement;
const rootName = root.nodeName;
const jsonData = xmlNodeToJS(root);
// Wrap the result in an object with the root tag name
const result = {};
result[rootName] = jsonData;
// 3. Stringify with pretty print
const jsonString = JSON.stringify(result, null, 2); // 2-space indent
// 4. Display the formatted text
const pre = document.createElement('pre');
pre.textContent = jsonString;
output.innerHTML = ''; // Clear previous output/placeholder
output.appendChild(pre);
// Enable buttons
copyBtn.disabled = false;
downloadBtn.disabled = false;
} catch (e) {
displayError(`An unexpected error occurred: ${e.message}`);
}
}
// --- Event Listeners ---
convertBtn.addEventListener('click', convertXMLtoJSON);
clearBtn.addEventListener('click', clearAll);
uploadBtn.addEventListener('click', () => fileUpload.click());
fileUpload.addEventListener('change', handleFileUpload);
copyBtn.addEventListener('click', copyOutput);
downloadBtn.addEventListener('click', downloadOutput);
});
Using this converter is straightforward. We’ve designed the interface to be distraction-free so you can get your code and get back to work.
Input Your Data:
Paste Code: Simply copy your WSDL (XML) code and paste it into the top text box.
Upload File: If you have a .wsdl or .xml file saved locally, click the “Upload File” button to load it directly.
Convert: Click the blue “Convert WSDL to JSON” button. The tool will process the tags and hierarchy instantly.
View and Copy: Your converted code will appear in the “JSON Output” box below. You can copy this text to your clipboard and use it immediately in your application.
Reset: If you need to start over, just hit the “Clear” button to empty the input fields.
Example
To give you an idea of how the transformation works, here is a simple comparison.
WSDL stands for Web Services Description Language. It is an XML-based language used to describe the functionality offered by a web service (SOAP). Developers convert it to JSON because JSON is lighter, faster to parse, and is the native data format for JavaScript and modern web APIs.
Is my WSDL data secure on this tool?
Yes. We prioritize user privacy. The conversion process runs automatically, and we do not store, save, or share the code you paste or the files you upload. Once you close or refresh the page, the data is gone.
Can I convert WSDL 2.0 files?
Yes, since WSDL 2.0 is valid XML, this tool will successfully parse the structure into JSON. However, the resulting JSON hierarchy will reflect the specific tag structure of WSDL 2.0.
What happens to the XML Namespaces during conversion?
Namespaces (like xmlns:tns) are treated as attributes. In the resulting JSON, you will typically find them inside an @attributes object associated with the parent tag, preserving the context of the data.