Install xml2js

npm install xml2js npm install @types/xml2js --save-dev

Program

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 = "<Employee><name>Aravind</name><age>24</age><sex>Male</sex></Employee>"
    // Result
    toJson(employeeXml);
    toXML(employeeJson);
////
/// SAMPLE OUTPUT 
////

{ Employee: { name: 'Aravind', age: '24', sex: 'Male' } }

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Employee>
  <name>Aravind</name>
  <age>24</age>
  <sex>Male</sex>
</Employee>
    

Aravind Appadurai

Aravin