Subscribe for notification
Software Tools

XML to JSON converter

NathTech’s Tools ,

 

XML to JSON converter    :

This is a responsive XML to JSON converter tool. You can input XML data, and it will convert it to JSON format when you click the “Convert” button. The styling is done using CSS, and Font Awesome library is used for the conversion icon.

 

 

 

XML to JSON Converter


function parseNode(node) { const obj = {};

if (node.nodeType === Node.TEXT_NODE) { return node.nodeValue.trim(); }

if (node.nodeType === Node.ELEMENT_NODE) { if (node.hasChildNodes()) { for (let childNode of node.childNodes) { const nodeName = childNode.nodeName;

if (nodeName in obj) { if (!Array.isArray(obj[nodeName])) { obj[nodeName] = [obj[nodeName]]; } obj[nodeName].push(parseNode(childNode)); } else { obj[nodeName] = parseNode(childNode); } } }

if (node.attributes.length > 0) { obj['@attributes'] = {}; for (let i = 0; i < node.attributes.length; i++) { const attribute = node.attributes[i]; obj['@attributes'][attribute.nodeName] = attribute.nodeValue; } } } return obj; } json[xmlDoc.documentElement.nodeName] = parseNode(xmlDoc.documentElement); return json; } function convert() { const xmlInput = document.getElementById('xmlInput').value.trim(); try { const jsonObject = xmlToJson(xmlInput); const jsonString = JSON.stringify(jsonObject, null, 2); document.getElementById('output').innerHTML = `

${jsonString}

`; } catch (error) { document.getElementById('output').innerHTML = `

Invalid XML format. Please enter valid XML.

`; } }

 

shmbhnthjh8

Music composer, blogger,website creator,freelancer

Recent Posts

Toncoin: Everything You Need to Know About the Future of this Unique Cryptocurrency

NathTech Guid,   Introduction to Toncoin (TON) Toncoin (TON) is the native cryptocurrency of The…

2 months ago

How to Get Naturally Glowing Skin: A Complete Guide for All Skin Types

NathTech Guide , Introduction: glowing skin is a reflection of overall health and self-care. While…

3 months ago

How to Get Glowing Skin: Essential Tips, Skin Care Components, and Protection Against Environmental Factors

NathTech Guid Introduction: Achieving glowing skin is a goal that many people aspire to, but…

3 months ago

Essential Components of Fitness: A Comprehensive Guide for All Ages

Nathtech Guideline , Introduction Maintaining fitness is crucial for a healthy and fulfilling life, regardless…

5 months ago

Maintaining Fitness Naturally: A Comprehensive Guide for All Ages

Nathtech Guideline ,   Introduction ; In today's fast-paced world, maintaining fitness is more than…

5 months ago

Unlocking Natural Fitness: Essential Tips for Every Age

Nathtech's Guideline ,     Introduction , In a world that is increasingly focused on…

5 months ago