{"id":14008583,"url":"https://github.com/kaue/jsonexport","last_synced_at":"2026-05-08T02:06:04.632Z","repository":{"id":40953518,"uuid":"33768051","full_name":"kaue/jsonexport","owner":"kaue","description":"{} → :page_facing_up: it's easy to convert JSON to CSV","archived":false,"fork":false,"pushed_at":"2024-05-14T15:54:31.000Z","size":832,"stargazers_count":247,"open_issues_count":17,"forks_count":42,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-17T08:02:54.897Z","etag":null,"topics":["cli","csv","export","javascript","json","json-objects","nodejs","npm","npm-module","npm-package"],"latest_commit_sha":null,"homepage":"http://kaue.github.io/jsonexport/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaue.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2015-04-11T08:08:53.000Z","updated_at":"2024-06-18T12:27:45.899Z","dependencies_parsed_at":"2024-06-18T12:27:39.262Z","dependency_job_id":"06319814-fa3e-4894-b153-f00d23e5a378","html_url":"https://github.com/kaue/jsonexport","commit_stats":{"total_commits":227,"total_committers":23,"mean_commits":9.869565217391305,"dds":0.5903083700440528,"last_synced_commit":"4a498777bab79dac88d32515b7ebd2086d8c6f41"},"previous_names":["kauegimenes/jsonexport"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaue%2Fjsonexport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaue%2Fjsonexport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaue%2Fjsonexport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaue%2Fjsonexport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaue","download_url":"https://codeload.github.com/kaue/jsonexport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237585880,"owners_count":19334287,"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":["cli","csv","export","javascript","json","json-objects","nodejs","npm","npm-module","npm-package"],"created_at":"2024-08-10T11:01:51.675Z","updated_at":"2026-05-08T02:06:04.596Z","avatar_url":"https://github.com/kaue.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jsonexport {} → 📄 \n\n[![Travis](https://travis-ci.org/kauegimenes/jsonexport.svg)](https://travis-ci.org/kauegimenes/jsonexport)\n[![Known Vulnerabilities](https://snyk.io/test/npm/jsonexport/badge.svg)](https://snyk.io/test/npm/jsonexport)\n[![NPM Version](http://img.shields.io/npm/v/jsonexport.svg?style=flat)](https://www.npmjs.org/package/jsonexport)\n[![NPM Downloads](https://img.shields.io/npm/dm/jsonexport.svg?style=flat)](https://www.npmjs.org/package/jsonexport)\n[![NPM Downloads](https://img.shields.io/npm/dt/jsonexport.svg?style=flat)](https://www.npmjs.org/package/jsonexport)\n[![NPM License](https://img.shields.io/npm/l/jsonexport.svg?style=flat)](https://www.npmjs.org/package/jsonexport)\n[![GitHub stars](https://img.shields.io/github/stars/kauegimenes/jsonexport.svg)](https://github.com/kaue/jsonexport/stargazers)\n[![Try jsonexport on RunKit](https://badge.runkitcdn.com/jsonexport.svg)](https://npm.runkit.com/jsonexport)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/jsonexport)\n\n✔ **easy to use** 👌 (should work as expected without much customization)️\n\n✔ **extendable** 🕺 (many options to customize the output)\n\n✔️ **tiny** 🐜 (0 dependencies) \n\n✔ **scalable** 💪 (works with big files using Streams)\n\n✔ **fast** ⚡ \n\n[Project Page](https://kaue.github.io/jsonexport/)\n\n[Online Demo Page](https://kaue.github.io/jsonexport/demo/)\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003eTable of Contents\u003c/b\u003e\u003c/summary\u003e\n\n- [Usage](#usage)\n- [CLI](#cli)\n- [Browser](#browser)\n  - [Browser Import Examples](#browser-import-examples)\n- [Stream](#stream)\n- [Promise](#promise)\n- [JSON Array Example](#json-array-example)\n  - [Simple Array](#simple-array)\n  - [JSON Object Example](#json-object-example)\n- [Options](#options)\n  - [typeHandlers](#typehandlers)\n- [Contributors](#contributors)\n\n\u003c/details\u003e\n\n\n# Usage\n\nInstallation command is `npm install jsonexport`.\n\nRun tests with `npm test`.\n\n```javascript\nconst jsonexport = require('jsonexport');\n\njsonexport({lang: 'Node.js', module: 'jsonexport'}, {rowDelimiter: '|'}, function(err, csv){\n    if (err) return console.error(err);\n    console.log(csv);\n});\n```\n\n## CLI\n\nGlobal installation command is `npm install -g jsonexport`.\n\nConvert JSON to CSV using `cat data.json | jsonexport` or `jsonexport data.json`\n\nUsage: `jsonexport \u003cJSON filename\u003e \u003cCSV filename\u003e`\n\n## Browser\nUse the code in the folder named **dist** to run jsonexport in the browser\n\n### Browser Import Examples\n\nWebpack\n```javascript\nconst jsonexport = require(\"jsonexport/dist\")\n```\n\nTypescript\n```javascript\nimport * as jsonexport from \"jsonexport/dist\"\n```\n\n## Stream\n\n```javascript\nconst jsonexport = require('jsonexport');\nconst fs = require('fs');\n\nconst reader = fs.createReadStream('data.json');\nconst writer = fs.createWriteStream('out.csv');\n\nreader.pipe(jsonexport()).pipe(writer);\n```\n\n## Promise\n\n```javascript\nconst jsonexport = require('jsonexport')\ntry {\n    const csv = await jsonexport({lang: 'Node.js', module: 'jsonexport'}, {rowDelimiter: '|'});\n} catch (err) {\n    console.error(err);\n}\n```\n\n## JSON Array Example\n\n### Simple Array\n\n#### Code\n\n```javascript\nconst jsonexport = require('jsonexport');\n\nconst contacts = [{\n    name: 'Bob',\n    lastname: 'Smith'\n},{\n    name: 'James',\n    lastname: 'David'\n},{\n    name: 'Robert',\n    lastname: 'Miller'\n},{\n    name: 'David',\n    lastname: 'Martin'\n}];\n\njsonexport(contacts, function(err, csv){\n    if (err) return console.error(err);\n    console.log(csv);\n});\n```\n\n#### Result\n\n```\nname,lastname\nBob,Smith\nJames,David\nRobert,Miller\nDavid,Martin\n```\n\n### Complex Array\n\n#### Code\n\n```javascript\nconst jsonexport = require('jsonexport');\n\nconst contacts = [{\n   name: 'Bob',\n   lastname: 'Smith',\n   family: {\n       name: 'Peter',\n       type: 'Father'\n   }\n},{\n   name: 'James',\n   lastname: 'David',\n   family:{\n       name: 'Julie',\n       type: 'Mother'\n   }\n},{\n   name: 'Robert',\n   lastname: 'Miller',\n   family: null,\n   location: [1231,3214,4214]\n},{\n   name: 'David',\n   lastname: 'Martin',\n   nickname: 'dmartin'\n}];\n\njsonexport(contacts, function(err, csv){\n    if (err) return console.error(err);\n    console.log(csv);\n});\n```\n\n#### Result\n\n```\nname,lastname,family.name,family.type,family,location,nickname\nBob,Smith,Peter,Father\nJames,David,Julie,Mother\nRobert,Miller,,,,1231;3214;4214\nDavid,Martin,,,,,dmartin\n```\n\n## JSON Object Example\n\n### Simple Object\n\n#### Code\n\n```javascript\nconst jsonexport = require('jsonexport');\n\nconst stats = {\n    cars: 12,\n    roads: 5,\n    traffic: 'slow'\n};\n\njsonexport(stats, function(err, csv){\n    if(err) return console.error(err);\n    console.log(csv);\n});\n```\n\n#### Result\n\n```\ncars,12\nroads,5\ntraffic,slow\n```\n\n### Complex Object\n\n#### Code\n\n```javascript\nconst jsonexport = require('jsonexport');\n\nconst stats = {\n    cars: 12,\n    roads: 5,\n    traffic: 'slow',\n    speed: {\n        max: 123,\n        avg: 20,\n        min: 5\n    },\n    size: [10,20]\n};\n\njsonexport(stats, function(err, csv){\n    if(err) return console.error(err);\n    console.log(csv);\n});\n```\n\n#### Result\n\n```\ncars,12\nroads,5\ntraffic,slow\nspeed.max,123\nspeed.avg,20\nspeed.min,5\nsize,10;20\n```\n\n## Options\n\nIn order to get the most of out of this module, you can customize many parameters and functions.\n\n- `headerPathString` - `String` Used to create the propriety path, defaults to `.` example `contact: {name: 'example}` = `contact.name`\n- `fillGaps` - `Boolean` Set this option if don't want to have empty cells in case of an object with multiple nested items (array prop), defaults to `false` [Issue #22](https://github.com/kaue/jsonexport/issues/22)\n- `fillTopRow` - `Boolean` try filling top rows first for unpopular colums, defaults to `false`\n- `headers` - `Array` Used to set a custom header order, defaults to `[]` example `['lastname', 'name']`\n- `rename` - `Array` Used to set a custom header text, defaults to `[]` example `['Last Name', 'Name']`\n- `mapHeaders` - `Function` Post-process headers after they are calculated with delimiters, example `mapHeaders: (header) =\u003e header.replace(/foo\\./, '')`\n- `rowDelimiter` - `String` Change the file row delimiter\n    - Defaults to `,` (**cvs format**).\n    - Use `\\t` for **xls format**.\n    - Use `;` for (**windows excel .csv format**).\n- `textDelimiter` - `String` The character used to escape the text content if needed (default to `\"`)\n- `forceTextDelimiter` - `Boolean` Set this option to true to wrap every data item and header in the textDelimiter. Defaults to `false`\n- `endOfLine` - `String` Replace the OS default EOL.\n- `mainPathItem` - `String` Every header will have the `mainPathItem` as the base.\n- `arrayPathString` - `String` This is used to output primitive arrays in a single column, defaults to `;`\n- `booleanTrueString` - `String` Will be used instead of `true`.\n- `booleanFalseString` - `String` Will be used instead of `false`.\n- `includeHeaders` - `Boolean` Set this option to false to hide the CSV headers.\n- `undefinedString` - `String` If you want to display a custom value for undefined strings, use this option. Defaults to ` `.\n- `verticalOutput` - `Boolean` Set this option to false to create a horizontal output for JSON Objects, headers in the first row, values in the second.\n- `typeHandlers` - `{typeName:(value, index, parent)=\u003eany` A key map of constructors used to match by instance to create a value using the defined function ([see example](#typehandlers))\n\n#### typeHandlers\nDefine types by constructors and what function to run when that type is matched\n\n```javascript\nconst jsonexport = require('jsonexport');\n\n//data\nconst contacts = {\n  'a' : Buffer.from('a2b', 'utf8'),\n  'b' : Buffer.from('other field', 'utf8'),\n  'x' : 22,\n  'z' : function(){return 'bad ace'}\n};\n\nconst options = {\n  //definitions to type cast\n  typeHandlers: {\n    Array:function(value,index,parent){\n      return 'replaced-array';\n    },\n    Boolean:function(value,index,parent){\n      return 'replaced-boolean';\n    },\n    Function:function(value,index,parent){\n      return value();\n    },\n    Number:function(value,index,parent){\n      return 'replaced-number';\n    },\n    String:function(value,index,parent){\n      return 'replaced-string';\n    },\n    Buffer:function(value,index,parent){\n      return value.toString();\n    }\n  }\n};\n\njsonexport(contacts, options, function(err, csv) {\n  if (err) return console.error(err);\n  console.log(csv);\n});\n```\n\nThe output would be:\n```\na,a2b\nb,other field\nx,replaced-number\nz,bad ace\n```\n\nDate typeHandler?\n\n```javascript\nvar date = new Date();\njsonexport({\n    a: date,\n    b: true\n}, {\n    typeHandlers: {\n        Object: (value, name) =\u003e {\n            if (value instanceof Date) return date.toLocaleString();\n            return value;\n        }\n    }\n}, (err, csv) =\u003e {\n    if (err) return console.error(err);\n    console.log(csv);\n});\n```\n\nWhen using **typeHandlers**, Do NOT do this\n\n```javascript\nconst options = {\n  typeHandlers: {\n    Object:function(value, index, parent){\n      return 'EVERYTHING IS AN OBJECT';\n    }\n  }\n};\n```\n\u003e It is NOT an error, however the recursive result becomes illegable functionality strings\n\n## Contributors\n- [Kauê Gimenes](https://github.com/kaue)\n- [Pierre Guillaume](https://github.com/papswell)\n- [Acker Apple](https://github.com/AckerApple) [![hire me](https://ackerapple.github.io/resume/assets/images/hire-me-badge.svg)](https://ackerapple.github.io/resume/)\n- [Victor Hahn](https://github.com/rv-vhahn)\n- [Jason Macgowan](https://github.com/jasonmacgowan)\n- [And many more...](https://github.com/kaue/jsonexport/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaue%2Fjsonexport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaue%2Fjsonexport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaue%2Fjsonexport/lists"}