There are many online services like this https://codebeautify.org/xmltojson , and they successfully do it.

What library can be used to achieve exactly the same result?

    2 answers 2

    Download the xml2json package

    npm install xml2json 

    Code for conversion:

     let xmlParser = require('xml2json');<br> let xmlString = строка-в-формате-xml; console.log('JSON после конвертации', xmlParser.toJson(xmlString)); 
        xml-to-json-stream 

      I chose this package: https://www.npmjs.com/package/xml-to-json-stream .

      Code:

        const xmlToJson = require('xml-to-json-stream'); const fs = require('fs'); const url = require('url'); const path = require('path'); const filePathIn = path.join(__dirname, 'in', 'feed.xml'); const fileStreamIn = fs.createReadStream(filePathIn); const filePathInOut = path.join(__dirname, 'out', 'feed.json'); const fileStreamInOut = fs.createWriteStream(filePathInOut); const parser = xmlToJson(); const stream = parser.createStream(); fileStreamIn.pipe(stream).pipe(fileStreamInOut);