Bindings for the xml2json C++ library to the Node.js world
npm install xml2json-napixml2json C++ library (https://github.com/Cheedoong/xml2json).
sh
$ npm install xml2json-napi
Or if you're using yarn
$ yarn add xml2json-napi
Or if you're using pnpm
$ pnpm install xml2json-napi
`
Please note that this package doesn't offer any options, as the original xml2json C++ library exclusively accepts the XML as a string and returns the resulting JSON-formatted string.
Given the following example:
`js
import { xml2json } from 'xml2json-napi';
const xml =
'' +
'' +
' Happy ' +
' Work ' +
' Play ' +
' ';
xml2json(xml);
// This will output the following string:
// '{"note":{"@importance":"high","@logged":"true","title":"Happy","todo":["Work","Play"]}}'
JSON.parse(xml2json(xml));
// Since this is a JSON-formatted string, we can pass it to JSON.parse:
// {
// note: {
// '@importance': 'high',
// '@logged': 'true',
// title: 'Happy',
// todo: [ 'Work', 'Play' ]
// }
// }
``