@biothings-explorer/json-transformer
v1.0.2
Published
a nodejs module to transform json output based on template
Downloads
31
Readme
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
- Website: http://github.com/kevinxin90
- Github: @kevinxin90
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!