{"id":16959293,"url":"https://github.com/chriskalmar/json-shaper","last_synced_at":"2025-04-11T22:08:52.795Z","repository":{"id":57285337,"uuid":"89787484","full_name":"chriskalmar/json-shaper","owner":"chriskalmar","description":"Shape a flat array into a molded json shape with deep nesting","archived":false,"fork":false,"pushed_at":"2020-08-25T02:56:16.000Z","size":96,"stargazers_count":3,"open_issues_count":9,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T22:08:46.881Z","etag":null,"topics":["array","json","schema","transform"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chriskalmar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-29T13:35:58.000Z","updated_at":"2021-12-09T22:02:47.000Z","dependencies_parsed_at":"2022-09-19T23:02:23.048Z","dependency_job_id":null,"html_url":"https://github.com/chriskalmar/json-shaper","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskalmar%2Fjson-shaper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskalmar%2Fjson-shaper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskalmar%2Fjson-shaper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskalmar%2Fjson-shaper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chriskalmar","download_url":"https://codeload.github.com/chriskalmar/json-shaper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487712,"owners_count":21112191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","json","schema","transform"],"created_at":"2024-10-13T22:44:40.171Z","updated_at":"2025-04-11T22:08:52.774Z","avatar_url":"https://github.com/chriskalmar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-shaper\n\n\n[![Build Status](https://travis-ci.org/chriskalmar/json-shaper.svg?branch=master)](https://travis-ci.org/chriskalmar/json-shaper)\n[![coverage](https://codecov.io/gh/chriskalmar/json-shaper/branch/master/graph/badge.svg)](https://codecov.io/gh/chriskalmar/json-shaper)\n[![npm version](https://badge.fury.io/js/json-shaper.svg)](https://www.npmjs.com/package/json-shaper)\n\nShape a flat array into a molded json shape with deep nesting\n\n## Installation\n\n#### yarn\n    $ yarn add json-shaper\n\n#### npm\n    $ npm install json-shaper --save\n\n## How to use\n\n```js\n// import shaper\nimport { shaper } from 'json-shaper';\n\n// load data to be transformed\nimport input from './data/input.js'\n\n\n// define a schema to shape by\nconst schema = {\n  id: 'id',\n  firstName: 'first_name',\n  lastName: 'last_name',\n  workplace: {\n    id: 'office_id',\n    name: 'office_company_name',\n    address: {\n      street: 'company_street',\n      postCode: 'company_postcode',\n      country: 'company_cty',\n    }\n  },\n  isActive: 'user_is_active'\n}\n\n\n// generate transformer function based on schema\nconst transformer = shaper(schema)\n\n// transform data\nconst result = input.map(transformer)\n\n// profit\nconsole.log(JSON.stringify(result, null, 2));\n```\n\n#### If the input data looks like this:\n```js\n[\n  {\n    \"id\": 32,\n    \"first_name\": \"John\",\n    \"last_name\": \"Flow\",\n    \"office_id\": 12,\n    \"office_company_name\": \"ACME Inc.\",\n    \"company_street\": \"Rocket Street 3\",\n    \"company_postcode\": \"11122\",\n    \"company_cty\": \"Space City\",\n    \"user_is_active\": false\n  },\n  {\n    \"id\": 100,\n    \"first_name\": \"Mike\",\n    \"last_name\": \"\",\n    \"office_id\": 532,\n    \"office_company_name\": \"\",\n    \"user_is_active\": true\n  },\n  ...\n  ...\n  ...\n]\n```\n\n#### json-shaper will transform it into this:\n```js\n[\n  {\n    \"id\": 32,\n    \"firstName\": \"John\",\n    \"lastName\": \"Flow\",\n    \"workplace\": {\n      \"id\": 12,\n      \"name\": \"ACME Inc.\",\n      \"address\": {\n        \"street\": \"Rocket Street 3\",\n        \"postCode\": \"11122\",\n        \"country\": \"Space City\",\n      }\n    },\n    \"isActive\": false\n  },\n  {\n    \"id\": 100,\n    \"firstName\": \"Mike\",\n    \"lastName\": \"\",\n    \"workplace\": {\n      \"id\": 532,\n      \"name\": \"\",\n      \"address\": {}\n    },\n    \"isActive\": true\n  },\n  ...\n  ...\n  ...\n]\n```\n\n## Performance / Benchmarks\n\n        // TODO\n\n## License\n\nMIT License\n\nCopyright (c) 2017 Chris Kalmar\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskalmar%2Fjson-shaper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchriskalmar%2Fjson-shaper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskalmar%2Fjson-shaper/lists"}