{"id":22013007,"url":"https://github.com/gone369/json-spread","last_synced_at":"2025-05-06T21:44:04.350Z","repository":{"id":57146676,"uuid":"61518341","full_name":"gone369/json-spread","owner":"gone369","description":"A simple javascript library that flattens a json structured object and then creates duplicate objects off of each nested array elements.","archived":false,"fork":false,"pushed_at":"2025-03-19T08:20:35.000Z","size":66,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T03:13:36.667Z","etag":null,"topics":["csv","flattens","javascript","javascript-library","json","nested-arrays","nested-objects"],"latest_commit_sha":null,"homepage":"","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/gone369.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-20T05:07:28.000Z","updated_at":"2025-03-19T08:20:38.000Z","dependencies_parsed_at":"2025-03-19T09:34:24.611Z","dependency_job_id":null,"html_url":"https://github.com/gone369/json-spread","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/gone369%2Fjson-spread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gone369%2Fjson-spread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gone369%2Fjson-spread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gone369%2Fjson-spread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gone369","download_url":"https://codeload.github.com/gone369/json-spread/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776268,"owners_count":21802459,"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":["csv","flattens","javascript","javascript-library","json","nested-arrays","nested-objects"],"created_at":"2024-11-30T03:16:29.400Z","updated_at":"2025-05-06T21:44:04.343Z","avatar_url":"https://github.com/gone369.png","language":"JavaScript","readme":"Json-Spread\n===========\n[![npm](https://img.shields.io/npm/v/json-spread.svg)](https://www.npmjs.com/package/json-spread) ![license](https://img.shields.io/npm/l/json-spread.svg) ![github-issues](https://img.shields.io/github/issues/gone369/json-spread.svg) ![npm-downloads](https://img.shields.io/npm/dt/json-spread.svg)\n\n\n## Description\n\nA simple javascript library that flattens a json structured object and then creates duplicate objects off of each nested array elements.\n\nGreat for converting nested, multi-leveled json to single level json that can be used to create csv,tsv,excel or other row column structured data.\n\n\n## Version 1.0.0\n- Added TS Support\n- ESM Support\n- CJS Backwards Compatibility \n- UMD Support\n\nyou can still use vanilla JS version of this package. Just lock the version at `v0.3.2`\n\n## Installation\n\n#### Node\n```bash\nnpm install json-spread\n```\n#### Browser\ninclude the `jsonSpread.js` file from the dist folder\n\n## [NEW!] TypeScript Support (v1.0.0)\n\nThis library includes TypeScript type definitions. You can use it in your TypeScript projects:\n\n```typescript\n// CommonJS style\nconst jsonSpread = require('json-spread');\n```\n// OR ES Module style\n\n```typescript\nimport jsonSpread from 'json-spread';\n\n// Use generics to specify the return type\ninterface MyData {\n  name: string;\n  value: number;\n}\n\nconst result = jsonSpread\u003cMyData\u003e(myData, { delimiter: '-' });\n```\n\n## Usage\n\n```javascript\nconst jsonSpread = require('json-spread');\nconst output = jsonSpread({\n  \"a\": [\n    {\n      \"index\": 1\n    },\n    {\n      \"index\": 2\n    },\n    {\n      \"index\": 3\n    }\n  ]\n})\n/*\noutput = [\n  {\n    \"a.index\": 1\n  },\n  {\n    \"a.index\": 2\n  },\n  {\n    \"a.index\": 3\n  }\n]\n*/\n```\n\n## Examples\n\nnested array\n```javascript\n//input\n{\n  \"a\": [\n    1,\n    2,\n    3\n  ],\n  \"b\": {\n    \"a\": [\n      1,\n      2,\n      3\n    ]\n  }\n}\n//output\n[\n  {\n    \"a\":1\n  },\n  {\n    \"a\":2\n  },\n  {\n    \"a\":3\n  },\n  {\n    \"b.a\":1\n  },\n  {\n    \"b.a\":2\n  },\n  {\n    \"b.a\":3\n  }\n]\n```\n\nnested arrays within nested objects\n```javascript\n//input\n{\n  \"a\": {\n    \"b\": {\n      \"c\": {\n        \"d\": {\n          \"e\" : {\n            \"array\": [\n              1,\n              2,\n              3\n            ]\n          }\n        }\n      }\n    }\n  }\n}\n//output\n[\n  {\n    \"a.b.c.d.e.array\": 1\n  },\n  {\n    \"a.b.c.d.e.array\": 2\n  },\n  {\n    \"a.b.c.d.e.array\": 3\n  }\n]\n```\n\nreal life example\n```javascript\n//input\n[\n  {\n    \"user_id\" : 1,\n    \"email\": \"1@domain.com\",\n    \"hobbies\": [\n      {\n        \"type\": \"sport\",\n        \"name\": \"soccer\",\n        \"dates\": [\n          \"May 3rd\",\n          \"May 4th\",\n          \"May 5th\"\n        ]\n      },\n      {\n        \"type\": \"sport\",\n        \"name\": \"basketball\",\n        \"dates\": [\n          \"June 3rd\",\n          \"July 4th\"\n        ]\n      }\n    ]\n  },\n  {\n    \"user_id\" : 2,\n    \"email\": \"2@domain.com\"\n  },\n  {\n    \"user_id\" : 3,\n    \"email\": \"3@domain.com\",\n    \"hobbies\": []\n  }\n]\n//output\n[{\n\t\"user_id\": 1,\n\t\"email\": \"1@domain.com\",\n\t\"hobbies.type\": \"sport\",\n\t\"hobbies.name\": \"soccer\",\n\t\"hobbies.dates\": \"May 3rd\"\n}, {\n\t\"user_id\": 1,\n\t\"email\": \"1@domain.com\",\n\t\"hobbies.type\": \"sport\",\n\t\"hobbies.name\": \"soccer\",\n\t\"hobbies.dates\": \"May 4th\"\n}, {\n\t\"user_id\": 1,\n\t\"email\": \"1@domain.com\",\n\t\"hobbies.type\": \"sport\",\n\t\"hobbies.name\": \"soccer\",\n\t\"hobbies.dates\": \"May 5th\"\n}, {\n\t\"user_id\": 1,\n\t\"email\": \"1@domain.com\",\n\t\"hobbies.type\": \"sport\",\n\t\"hobbies.name\": \"basketball\",\n\t\"hobbies.dates\": \"June 3rd\"\n}, {\n\t\"user_id\": 1,\n\t\"email\": \"1@domain.com\",\n\t\"hobbies.type\": \"sport\",\n\t\"hobbies.name\": \"basketball\",\n\t\"hobbies.dates\": \"July 4th\"\n}, {\n\t\"user_id\": 2,\n\t\"email\": \"2@domain.com\"\n}, {\n\t\"user_id\": 3,\n\t\"email\": \"3@domain.com\",\n\t\"hobbies\": null\n}]\n```\n\n## Options\n\n### Fields\n\n##### delimiter\nspecify the delimiting value for nested objects.\n\n```javascript\nconst data = { \"a\": { \"b\" : \"foo\"} };\nconst options = {\n  delimiter : \"*\" //default is '.'\n}\nconst output = jsonSpread(data,options);\n//output\n{\n  \"a*b\" : \"foo\"\n}\n```\n\n##### removeEmptyArray\nremoves empty arrays\n\n```javascript\nconst data = { \"a\": \"value_a\" , \"b\": []};\nconst options = {\n  removeEmptyArray: true //default is false\n}\nconst output = jsonSpread(data,options);\n//output\n{\n  \"a\" : \"value_a\"\n}\n```\n##### emptyValue\nyou can define the value for empty arrays in options.  \nthis is ignored if removeEmptyArray is ``true``\n\n```javascript\nconst data = { \"a\": [] };\nconst options = {\n  emptyValue: \"EMPTY\" //default is null\n}\nconst output = jsonSpread(data,options);\n//output\n{\n  \"a\" : \"EMPTY\"\n}\n```\n\n## Contributing\n\n###### installation\nFork it, then do an ``npm install``. everything should be in there  \n\n###### building\nafter writing in src folder, do:\n```bash\nnpm run build\n```\nto see if it builds\n\n###### tests\nI use mocha and chai to test. \n```bash\nnpm test\n```\nwrite tests in ``/test`` folder. \n\n## Dependencies\nThis library currently depends on [flat](https://www.npmjs.com/package/flat)\n\n## License\nMIT License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgone369%2Fjson-spread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgone369%2Fjson-spread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgone369%2Fjson-spread/lists"}