import { parseString, Builder } from "xml2js"; // Convert string/XML to JSON function toJson(xml: string) { parseString(xml, { explicitArray: false }, function(error, result) { console.log(result); }); } // Convert string/JSON to XML function toXML(json: string) { const builder = new Builder(); console.log(builder.buildObject(json)); } // Test Data const employeeJson: any = { Employee: { name: 'Aravind', age: 24, sex: 'Male' } }; const employeeXml = "Aravind24Male" // Result toJson(employeeXml); toXML(employeeJson); //// /// SAMPLE OUTPUT //// { Employee: { name: 'Aravind', age: '24', sex: 'Male' } } Aravind 24 Male