Created
September 17, 2014 18:28
-
-
Save hrwgc/2016f652f41e1185d241 to your computer and use it in GitHub Desktop.
convert xml to json nodejs command line utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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