node-json2xml
Description
Simple JavaScript Object to XML string converter.
Installation
Install via npm, which will download json2xml
and all of its dependencies.
npm install json2xml
Simple usage
While the name of the repo is json2xml
, it is really pojo2xml
, since you will need to run JSON.parse
on the JSON data prior to converting.
var fs = require('fs');
var json2xml = require('json2xml');
fs.readFile('data.json', 'utf8', function read (err, data) {
if (err) console.log(err);
fs.writeFile('data.xml', json2xml(JSON.parse(data)));
});
Options & Behaviour
json2xml({ a: 1 });
json2xml({ a: '' });
json2xml({ a: 1 }, { header: true });
json2xml({ a: 1, attr: { b: 2, c: 3 } }, { attributes_key: 'attr' });
json2xml([ { a: 1 }, { b: 2 } ]);
json2xml({ 'items': [ { item: 1 }, { item: 2 } ] });