I am trying to convert the JSON to XML but not getting exact output.In My JSON having array object it not converting that to XML array.Mainly array object is not converti
const objectToXml = (object) => Object.keys(object).reduce((reqStr, key) => {
const value = object[key] || '';
const isObject = typeof value === 'object';
const isArray = Array.isArray(value);
if (isArray) {
return reqStr + value.reduce((accumulator, currentValue) =>
accumulator + `<${key}>${ typeof currentValue === 'object' ? objectToXml(currentValue) : (currentValue || '')}${key}>`
,'');
}
if (isObject) {
return reqStr + `<${key}>${objectToXml(value)}${key}>`;
}
return reqStr + `<${key}>${value}${key}>`;
}, '');
const output = objectToXml(yourJson);
console.log(output);