I'm attempting to convert a complex JSON object to XML using this package - XML.
var xml = require("xml");
var obj = { MS : { ts : 3423523, isOk : false , errors : [] }};
var xmlObj = xml(obj); // This outputs <MS/>
Any ideas how to make the XML parser go deeper? Why is it prematurely closed?
You could give the xml2js module a try, this would convert your object to Xml quite easily, e.g.
const xml2js = require('xml2js');
const obj = { MS : { ts : 3423523, isOk : false , errors : [] }};
const builder = new xml2js.Builder( { headless: false, renderOpts: { pretty: true } });
const xml = builder.buildObject(obj);
console.log(xml)
The output would be:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MS>
<ts>3423523</ts>
<isOk>false</isOk>
</MS>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With