Skip to content

Instantly share code, notes, and snippets.

@tmanolat
Created September 7, 2016 14:59
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 tmanolat/8d81a09dfa98849afe4996a1b870256f to your computer and use it in GitHub Desktop.
Save tmanolat/8d81a09dfa98849afe4996a1b870256f to your computer and use it in GitHub Desktop.
node.js convert a json file to xml
var fs = require('fs');
var xml2js = require('xml2js');
var builder = new xml2js.Builder();
var content = fs.readFileSync('data.json');
var o = JSON.parse(content);
var res = [];
o.forEach(function(r){
res.push(r);
});
var xml = builder.buildObject(res);
fs.writeFileSync('out.xml', xml);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment