XML Parser :Convert xml file to json or csv file

How to convert XML to JSON using JavaScript | convert xml to json

Pre-requisite :

npm install fs xmljs

Code :

var fs = require(‘fs’)

var convertXMLtoJson = require(‘xml2js’)

var xmldata = ‘?xml version=”1.0″ encoding=”UTF-8″?’ + ‘Student’ +

‘PersonalInformation’ + ‘FirstNameA/FirstName’ +

‘LastNameB/LastName’ +

‘GenderMale/Gender’ +

‘/PersonalInformation’ + ‘

PersonalInformation’ +

‘FirstNameC/FirstName’ +

‘LastNameD/LastName’ +

‘GenderMale/Gender’ +

‘/PersonalInformation’ +

‘/Student’;

convertXMLtoJson.parseString(xmldata,function(err,results){ fs.writeFile(“xmlToJson.json”,JSON.stringify(results),function(err){ console.log(‘JSON file is generated’) }) })

chapters :

0:00 – Introduction to convert xml to json

0:24 – Pre-requisite installation of package

0:57 – Program to convert xml to json

4:24 – Execution of the program

5:15 – End Tags and subscription to the channel

Share this post with your friends

×

Hello!

Hi there! How can I help you, %visitor.name%? Are you searching for anything else?

Start a Chat