1.0.2 ā€¢ Published 4 years ago

@biothings-explorer/json-transformer v1.0.2

Weekly downloads
51
License
ISC
Repository
github
Last release
4 years ago

Build Status Coverage Status

Welcome to @biothings-explorer/json-transformer šŸ‘‹

A nodejs module to transform JSON output based on template

šŸ  Homepage

Install

npm i @biothings-explorer/json-transformer

Usage

  • Import and Initialize

    const transform = require("@biothings-explorer/json-transformer")
  • Transform JSON object based on template file

    • Transform Plain JSON Object

      const json_doc = {'ensemblgene': 1017};
      // the template is a JSON object, with value as the field from json_doc to be transformed and the key as the field to be transformed to
      const template = {'ensembl': 'ensemblgene'};
      transform(json_doc, template); // returns {'ensembl': 1017}
    • Transform Nested JSON Object

      let json_doc = {
          'ensembl': {
              'gene': 1017
          }
      };
      let template = {'ensembl': 'ensembl.gene'};
      transform(json_doc, template); // returns {'ensembl': 1017}
    • Nested Template

      let json_doc = {
          'ensembl': {
              'gene': 1017
          },
          'wikipathway': [
              {
                  'id': 'WP123',
                  'name': 'aaa'
              },
              {
                  'id': 'WP1234',
                  'name': 'aaaa'
              }
          ]
      };
      let template = {
          'ensembl': 'ensembl.gene',
          'pathway': {
              'id': 'wikipathway.id',
              'name': 'wikipathway.name'
          }
      };
      let res = transform(json_doc, template); //returns {'ensembl': 1017, 'pathway': [{'id': 'WP123', 'name': 'aaa'}, {'id': 'WP1234', 'name': 'aaaa'}]}

Run tests

npm run test

Author

šŸ‘¤ Jiwen Xin

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2020 Jiwen Xin. This project is ISC licensed.

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago