@biothings-explorer/json-transformer

1.0.2 • Public • Published

Build Status Coverage Status Documentation Version

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.

Package Sidebar

Install

npm i @biothings-explorer/json-transformer

Weekly Downloads

2

Version

1.0.2

License

ISC

Unpacked Size

37 kB

Total Files

8

Last publish

Collaborators

  • ericz1803
  • kevinxin
  • marcocano
  • newgene