xml2js-clean
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

The package xml2js converts xml to json. In general, the problem is not easy since there are some ambiguities to be addressed. For this reason, xml2js produces a not very clean output.

This package tries to apply some heuristics to clean xml2js output.

Heuristics should be based on some known assumptions on the underlying xml schema.

Users can define their own heuristics, too.

Example

cleanXml(xml, {
  operations: [ // plug in the heuristics to apply
    simplifyArrayValues,
    transformEnglishSingularNamesToArray,
    parseNumericValues,
  ]
});

Input

sample: {
  title: 'fee',
  number: '2.4',
  integer: '399',
  items: {
    item: [ 'foe', 'foo' ]
  },
  entities: {
    entity: [
      { hello: 'world' },
      { hello: 'mum' },
    ]
  }
}

Output

sample: {
  title: 'fee',
  number: 2.4,
  integer: 399,
  items: [ 'foe', 'foo' ],
  entities: [
    { hello: 'world' },
    { hello: 'mum' },
  ]
}

Credits

The idea is discussed in this answer on Stackoverflow and is implemented in this package by Tristian Flanagan. This package is a rewriting of his code to make it more reusable and flexible.

Readme

Keywords

none

Package Sidebar

Install

npm i xml2js-clean

Weekly Downloads

3

Version

0.0.3

License

MIT

Unpacked Size

10.8 kB

Total Files

9

Last publish

Collaborators

  • mstn