xml2json-napi
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

xml2json-napi

Node.js library that offers bindings for the xml2json C++ library (https://github.com/Cheedoong/xml2json).

To install the package, execute the following command:

$ 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:

import { xml2json } from 'xml2json-napi';

const xml =
  '<?xml version="1.0" encoding="utf-8"?>' +
  '<note importance="high" logged="true">' +
  '    <title>Happy</title>' +
  '    <todo>Work</todo>' +
  '    <todo>Play</todo>' +
  '</note>';

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' ]
//   }
// }

Readme

Keywords

none

Package Sidebar

Install

npm i xml2json-napi

Weekly Downloads

146

Version

0.0.2

License

MIT

Unpacked Size

2.24 MB

Total Files

71

Last publish

Collaborators

  • overthesanity