Skip to content

Instantly share code, notes, and snippets.

@hrwgc
Created September 17, 2014 18:28
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 hrwgc/2016f652f41e1185d241 to your computer and use it in GitHub Desktop.
Save hrwgc/2016f652f41e1185d241 to your computer and use it in GitHub Desktop.
convert xml to json nodejs command line utility
#!/usr/bin/env node
var parser = require('xml2json');
var fs = require('fs');
function onFile(err, data) {
if (err) {
console.log('Uh oh: ' + err);
return;
}
var json = parser.toJson(data);
fs.writeFile(fpath.replace('.xml','.json'), json, function (err) {
if (err) throw err;
console.log(fpath.replace('.xml','.json') + ' saved!');
})
}
var fpath = process.argv[2];
var xml = fs.readFile(fpath, 'utf8',onFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment