json-xml-json
TypeScript icon, indicating that this package has built-in type declarations

2.1.3 • Public • Published

json-xml-json

This NPM package exposes a GenericParser and SubscriptionParser using saxophone-ts and fast-json-parse to convert a XML with JSON data.

The GenericParser is used to parse the whole XML document using saxophone-ts library into a JSON.

Whereas, SubscriptionParser used a json mapping to identify specific element and returns them in a flat structure.

Please note the SubscriptionParser will flatten the XML out based on the mapping provided The tag must be unique, otherwise the tag values will be packed as an array with all the values.

test data

usage

Please refer to test cases in the repository.

subscription based parsing

const xml = fs.readFileSync('./data/test_2.xml');
const soapParser = new SubscriptionParser<any>();
const subscriptionReq = [
  { tag: 'Envelope.Body.pa.paReq.refId', name: 'refId' },
  { tag: 'Envelope.Body.pa.paReq.ced.id', name: 'ids' },
  { tag: 'Envelope.Header.activity.activityDetails.activityId', name: 'actId' },
  { tag: 'Envelope.Body.dataJson', name: 'json', converter: dataJsonConverter },
];
const response = await soapParser.subscribe(subscriptionReq).parse(xml);

parsing full XML into a JSON object

const xml = fs.readFileSync('./data/test_1.xml');
const soapParser = new GenericParser<any>();
const response = await soapParser.parse(xml);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.3
    0
    • latest

Version History

Package Sidebar

Install

npm i json-xml-json

Weekly Downloads

0

Version

2.1.3

License

ISC

Unpacked Size

19.6 kB

Total Files

14

Last publish

Collaborators

  • agrawald