Skip to content

Instantly share code, notes, and snippets.

@freshyill
Created May 2, 2017 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freshyill/8c3fe8513c3ec2e6346a4c8afbb6cdf9 to your computer and use it in GitHub Desktop.
Save freshyill/8c3fe8513c3ec2e6346a4c8afbb6cdf9 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const convert = require('xml2json');
const xmlDir = 'final_xml';
fs.readdir(xmlDir, (err, xmlList) => {
for (let xmlFile of xmlList) {
fs.readFile(xmlDir + "/" + xmlFile, "utf-8", (err, fileContents) => {
if (err) throw err;
const newJson = convert.toJson(fileContents);
const jsonFileName = xmlFile.replace('.xml','.json');
fs.writeFile("issueJson/" + jsonFileName, newJson, function (err) {
if (err) {
console.log("Something went wrong!");
} else {
console.log("Created " + jsonFileName)
}
})
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment