I've used xml-js - npm to get the desired result.

First of all I've installed xml-js via npm install xml-js

Then used the below code to get the output in json format

var convert = require('xml-js');
var xml = require('fs').readFileSync('./testscenario.xml', 'utf8');

var result = convert.xml2json(xml, {compact: true, spaces: 4});
console.log(result);
Answer from Dinesh on Stack Overflow
🌐
npm
npmjs.com › search
xml to json - npm search
xml-to-json-util is a simple and efficient utility library for converting XML data to JSON format easily. typescript · npm · xml-to-json-util · util · andredrumond1995• 1.0.1 • 2 years ago • 0 dependents • MITpublished version 1.0.1, ...
Discussions

The KDL Document Language, an alternative to YAML/JSON/XML
Oh shit, another one. (Someone squash it before it gets away.) More on reddit.com
🌐 r/programming
258
448
September 12, 2021
Blazing fast XML parser to JSON for Node.js written in Rust
This appears to be almost an order of magnitude slower than xml-conv-json Package Time taken ---------------------------------- ---------- parser-xml2json (rust) 0.0661 s parser-xml2json (rust, no obj) 0.0649 s xml2js (js) 0.2056 s xml2json (js and c++) 0.1868 s xml-conv-json (c++) 0.0078 s xml-conv-json (c++ and JSON.parse) 0.0113 s EDIT: These benchmarks run on a 2013 MacBook Air 1.3 GHz i5 on macOS 10.12.3 on battery power, so YMMV. EDIT2: Thermal limiting seems to matter. By reordering the tests, the performance difference on my machine is noticeable: Package Time taken ---------------------------------- ---------- xml-conv-json (c++) 0.0066 s xml-conv-json (c++ and JSON.parse) 0.0077 s parser-xml2json (rust) 0.0708 s parser-xml2json (rust, no obj) 0.0710 s xml2js (js) 0.2128 s xml2json (js and c++) 0.2034 s More on reddit.com
🌐 r/node
6
13
October 21, 2016
Convert XML to a (useful) JSON
Have a look at xpath More on reddit.com
🌐 r/reactjs
2
1
December 25, 2023
HTML conversion into JSON

If the content (text, in your case) is within another tag, that content is a child of the tag. If the text is within a div, the div is the parent and the text is the child. So if you select the div, the content would obviously be in the children.

However your question seems less to do with html->JSON and more so on how to find content using cheerio. Cheerio is just server-side jQuery. So most, if not all, of jQuery’s methods can be used here, removing the need to traverse the JSON yourself.

More on reddit.com
🌐 r/node
7
7
July 13, 2016
🌐
npm
npmjs.com › package › xml2js
xml2js - npm
Simple XML to JavaScript object converter.. Latest version: 0.6.2, last published: 3 years ago. Start using xml2js in your project by running `npm i xml2js`. There are 10731 other projects in the npm registry using xml2js.
      » npm install xml2js
    
Published   Jul 26, 2023
Version   0.6.2
Author   Marek Kubica
🌐
npm
npmjs.com › package › simple-xml-to-json
simple-xml-to-json - npm
September 14, 2024 - const {convertXML, createAST} = require("simple-xml-to-json") const myJson = convertXML(myXMLString) const myYaml = convertXML(myXMLString, yamlConverter) const myAst = createAST(myXMLString)
      » npm install simple-xml-to-json
    
Published   Sep 14, 2024
Version   1.2.3
Author   Nir Moav
🌐
npm
npmjs.com › package › xml-js
xml-js - npm
February 13, 2019 - A convertor between XML text and Javascript object / JSON text.. Latest version: 1.6.11, last published: 7 years ago. Start using xml-js in your project by running `npm i xml-js`. There are 1987 other projects in the npm registry using xml-js.
      » npm install xml-js
    
Published   Feb 13, 2019
Version   1.6.11
Author   Yousuf Almarzooqi
🌐
npm
npmjs.com › package › xml2json
xml2json - npm
December 26, 2019 - Converts xml to json and vice-versa, using node-expat.. Latest version: 0.12.0, last published: 6 years ago. Start using xml2json in your project by running `npm i xml2json`. There are 624 other projects in the npm registry using xml2json.
      » npm install xml2json
    
Published   Dec 26, 2019
Version   0.12.0
🌐
npm
npmjs.com › package › xml-to-json-stream
xml-to-json-stream - npm
Latest version: 1.1.0, last published: 7 years ago. Start using xml-to-json-stream in your project by running `npm i xml-to-json-stream`. There are 7 other projects in the npm registry using xml-to-json-stream.
      » npm install xml-to-json-stream
    
Published   Feb 17, 2019
Version   1.1.0
Author   Alexander La Bianca
Find elsewhere
🌐
npm
npmjs.com › package › xmltojson
xmltojson - npm
Configurable, lightweight XML to JSON converter.. Latest version: 1.3.5, last published: 8 years ago. Start using xmltojson in your project by running `npm i xmltojson`. There are 9 other projects in the npm registry using xmltojson.
      » npm install xmltojson
    
Published   Aug 27, 2017
Version   1.3.5
Author   William Summers
🌐
Attacomsian
attacomsian.com › blog › nodejs-convert-xml-to-json
How to convert XML to JSON in Node.js
October 1, 2022 - To perform the XML to JSON conversion, we'll be using the xml2js module from Node Package Manager (NPM).
🌐
npm
npmjs.com › package › @jdalton › simple-xml-to-json
@jdalton/simple-xml-to-json - npm
May 22, 2024 - const {convertXML, createAST} = require("simple-xml-to-json") const myJson = convertXML(myXMLString) const myYaml = convertXML(myXMLString, yamlConverter) const myAst = createAST(myXMLString)
      » npm install @jdalton/simple-xml-to-json
    
Published   May 22, 2024
Version   1.2.14
Author   John-David
🌐
npm
npmjs.com › search
XML2JSON - npm search
Converts xml to json and vice-versa, using node-expat.
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › convert-xml-data-into-json-using-node-js
Convert XML data into JSON using Node.js - GeeksforGeeks
July 23, 2025 - To convert XML to JSON in Node we will use libraries like xml2js. First, parse the XML string, then transform it into JSON format, enabling easier manipulation of the data. Step 1: Install Modules: npm install xml2js · The updated dependencies ...
🌐
GitHub
github.com › max-mapper › xml-json
GitHub - max-mapper/xml-json: convert xml to json on the command line. not streaming, pure javascript · GitHub
convert xml to json on the command ... all nodes that match your filter node name will be returned one at a time as JSON. npm install xml-json -g xml-json <file> <xml node name>...
Starred by 37 users
Forked by 2 users
Languages   JavaScript
🌐
npm
npmjs.com › package › rapid-xml-to-json › v › 0.1.0
rapid-xml-to-json - npm
Latest version: 0.1.3, last published: 8 months ago. Start using rapid-xml-to-json in your project by running `npm i rapid-xml-to-json`. There are 1 other projects in the npm registry ...
      » npm install rapid-xml-to-json
    
Published   Jan 08, 2025
Version   0.1.0
Author   Christian Pilegaard Cederquist
🌐
Devextent
devextent.com › npm-convert-json-to-xml
Convert JSON to XML with the XML npm package | Dev Extent
March 23, 2021 - This way we can use async/await syntax. In the ConvertJsonToXml function the first thing we can do is read the JSON file containing a sample JSON object that we can convert to an XML string.
🌐
Lanceleonard
lanceleonard.com › tips › nodejs › xml-to-json
Convert XML to JSON | Lance's Quips & Quibbles
July 30, 2024 - var fs = require( 'fs' ), x2j = require( 'xml2js' ); var sInputFile = "books.xml;" var p = new x2j.Parser(); var sXMLData = fs.readFileSync( sInputFile, 'utf8' ); p.parseString( sXMLData, function( err, result ) { var s = JSON.stringify( result, undefined, 3 ); console.log( "Result" + "\n", s, "\n" ); }); Here, the input file (books.xml) is read into a string variable and then parsed. The result is passed to an anonymous function that formats it before printing it to the console.
🌐
Medium
pshreyasgowda1997.medium.com › converting-xml-to-json-format-using-node-js-in-two-different-scenario-43e0a33abe75
Conversion of XML to JSON Format Using Node.Js in Two Different Scenario | by Shreyas Prabhakar | Medium
June 5, 2021 - xmlFormat= convert.js2xml(js, options); // to convert javascript object to xml text · 2. xmlFormat= convert.json2xml(json, options); // to convert json text to xml text
🌐
npm
npmjs.com › package › xml-json
xml-json - npm
convert xml to json on the command ... all nodes that match your filter node name will be returned one at a time as JSON. npm install xml-json -g xml-json <file> <xml node name>...
      » npm install xml-json
    
Published   Aug 05, 2014
Version   2.0.2
Author   max ogden
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to convert xml to json in node.js
How to Convert XML to JSON in Node.js - Coding Beauty
November 12, 2022 - We can pass an object with a spaces option to properly format and indent the resulting JSON. import { xml2json } from 'xml-js'; const xml = `<?xml version="1.0" encoding="UTF-8"?> <languages> <language> English </language> <language> French </language> <language> Spanish </language> </languages>`; // 👇 Set "spaces" option const json = xml2json(xml, { spaces: 2 }); console.log(json);