All Rounder Tools Blogger-Best blog for blogger: JSON to XML Tool with colorful styling and all its features use any free library

Saturday, October 12, 2024

JSON to XML Tool with colorful styling and all its features use any free library

 

JSON to XML Converter

JSON to XML Converter

XML Output

body { font-family: Arial, sans-serif; background-color: #f0f4f8; color: #333; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); padding: 20px; width: 90%; max-width: 600px; } h1 { text-align: center; color: #4A90E2; } textarea { width: 100%; height: 150px; margin: 10px 0; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; resize: none; } textarea:focus { border-color: #4A90E2; outline: none; } button { background-color: #4A90E2; color: white; border: none; padding: 10px 15px; border-radius: 4px; cursor: pointer; width: 100%; } button:hover { background-color: #357ABD; } h2 { margin-top: 20px; color: #4A90E2; } document.getElementById('convertButton').addEventListener('click', function() { const jsonInput = document.getElementById('jsonInput').value; const xmlOutput = document.getElementById('xmlOutput'); try { const jsonObject = JSON.parse(jsonInput); const xmlString = jsonToXml(jsonObject); xmlOutput.value = xmlString; } catch (e) { xmlOutput.value = 'Invalid JSON input!'; } }); function jsonToXml(json) { let xml = ''; for (const prop in json) { if (json.hasOwnProperty(prop)) { xml += `<${prop}>`; if (typeof json[prop] === 'object' && !Array.isArray(json[prop])) { xml += jsonToXml(json[prop]); } else if (Array.isArray(json[prop])) { json[prop].forEach(item => { xml += `<${prop}>${jsonToXml(item)}</${prop}>`; }); } else { xml += json[prop]; } xml += `</${prop}>`; } } return xml; }

No comments:

Post a Comment