oozcitak / xmlbuilder-js

An XML builder for node.js
MIT License
918 stars 107 forks source link

XML to JSON #237

Closed ashishgehlot closed 4 years ago

ashishgehlot commented 4 years ago

Hi guys, Its really wonderful library to build XML. I have requirement to generate JSON from XML again. Is their any function ?

oozcitak commented 4 years ago

Yes. See the convert function and serialization settings for details:

const { convert } = require('xmlbuilder2');

const jsonObj = '{ "root": "node": { } }';
const xml = convert(jsonObj, { format: 'xml' });
console.log(xml);
<?xml version="1.0"?><root><node/></root>
ashishgehlot commented 4 years ago

Thanks @oozcitak Its really helpful.