{"id":18326438,"url":"https://github.com/limoer96/csv2json","last_synced_at":"2026-05-02T03:07:09.980Z","repository":{"id":44022847,"uuid":"198632202","full_name":"Limoer96/csv2json","owner":"Limoer96","description":"A Tool convert CSV to JSON or JS Object with no dependencies.","archived":false,"fork":false,"pushed_at":"2023-01-05T03:32:28.000Z","size":1771,"stargazers_count":0,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-28T07:56:34.958Z","etag":null,"topics":["csv","json"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Limoer96.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-24T12:34:02.000Z","updated_at":"2023-01-31T17:26:39.000Z","dependencies_parsed_at":"2023-02-03T09:01:13.324Z","dependency_job_id":null,"html_url":"https://github.com/Limoer96/csv2json","commit_stats":null,"previous_names":["xiaomoer/csv2json"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Limoer96/csv2json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limoer96%2Fcsv2json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limoer96%2Fcsv2json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limoer96%2Fcsv2json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limoer96%2Fcsv2json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Limoer96","download_url":"https://codeload.github.com/Limoer96/csv2json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limoer96%2Fcsv2json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32521114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","json"],"created_at":"2024-11-05T19:06:56.101Z","updated_at":"2026-05-02T03:07:09.961Z","avatar_url":"https://github.com/Limoer96.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# csv2jsonfile\r\n\r\n[![Build Status](https://travis-ci.com/xiaomoer/csv2json.svg?branch=master)](https://travis-ci.com/xiaomoer/csv2json)![Codecov](https://img.shields.io/codecov/c/github/xiaomoer/csv2json)![npm](https://img.shields.io/npm/dm/csv2jsonfile)![npm bundle size](https://img.shields.io/bundlephobia/min/csv2jsonfile)\r\n\r\n\u003e A Tool convert CSV to JSON or JS Object with NO Dependencies.\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install --save csv2jsonfile\r\n```\r\nor\r\n```bash\r\nyarn add csv2jsonfile\r\n```\r\nsee from [npm package](https://npmjs.org/package/csv2jsonfile).\r\n\r\n## Usage\r\n\r\n\u003e note: the csv file must have header(used as key), like the example below:\r\n```\r\ncity,level,alias\r\nShanghai,3,SH\r\nChongqing,3,SQ\r\nJinan,4,JN \r\n```\r\n\r\n### CSV to JSON\r\n```javascript\r\nconst csv2jsonfile = require('csv2jsonfile');\r\nconst path = require('path');\r\nconst sourcePath = path.resolve(__dirname, 'data.csv'); \r\nconst targetPath = path.resolve(__dirname, 'result.json');\r\n\r\n// default convert CSV with header\r\ncsv2jsonfile(sourcePath, targetPath)\r\n  .then((time) =\u003e {\r\n    console.log(`use: ${time} ms`);\r\n  })\r\n  .catch((err) =\u003e {\r\n    console.log(err.message);\r\n  })\r\n// result in result.json\r\n/*\r\n[\r\n  {\r\n    city: \"Shangehai\",\r\n    level: \"3\",\r\n    alias: \"SH\"\r\n  },\r\n  {\r\n    city: \"Chongqing\",\r\n    level: \"3\",\r\n    alias: \"CQ\"\r\n  },\r\n]\r\n*/\r\n// CSV without header\r\ncsv2jsonfile(sourcePath, targetPath, { header: false })\r\n  .then((time) =\u003e {\r\n    console.log(`use: ${time} ms`);\r\n  })\r\n  .catch((err) =\u003e {\r\n    console.log(err.message);\r\n  })\r\n```\r\n\r\n### CSV to JavaScript Object\r\n\r\n```javascript\r\nvar csv2jsonfile = require('csv2jsonfile');\r\ncsv2jsonfile.inline('data.csv')\r\n  .then((obj) =\u003e {\r\n    console.log(obj)\r\n  })\r\n  .catch((err) =\u003e {\r\n    console.log(err);\r\n  })\r\n// CSV without header\r\ncsv2jsonfile.inline('data.csv', { header: false })\r\n  .then((obj) =\u003e {\r\n    console.log(obj);\r\n  })\r\n  .catch((err) =\u003e {\r\n    console.log(err);\r\n  })\r\n```\r\n## API\r\n\r\n```javascript\r\n/**\r\n * convert csv to json file\r\n * @param {string} sourcePath absolute path of csv file \r\n * @param {string} targetPath absolute path of json file\r\n * @param {object} options default { header: true }\r\n * @return {Promise} ms usage through convert progress\r\n */\r\ncsv2jsonfile(sourcePath, targetPath, options?)\r\n\r\n/**\r\n *  convert csv to javascript object\r\n * @param {string} sourcePath absolute path of csv file\r\n * @param {object} options default { header: true }\r\n * @return {Promise} the object after convert\r\n */\r\ncsv2jsonfile.inline(sourcePath, options?)\r\n```\r\n## ChangeLog\r\n\r\n### v1.2.0\r\n1. Delete `targetPath` file if it exists before convert.(no need to manuallt clear)\r\n2. add **No Header** CSV support.\r\n\r\nIf the CSV without header, It will be converted into **Array** each line.\r\nE.g:\r\n\r\n```javascript\r\n// data.csv =\u003e data.json\r\n// 1. without header\r\n[\r\n  [\"Shanghai\", \"3\", \"SH\"],\r\n  [\"Chongqing\", \"3\", \"CQ\"],\r\n  [\"Jinan\", \"4\", \"JN\"]\r\n]\r\n// with header\r\n[\r\n  {\r\n    \"city\": \"Shanghai\",\r\n    \"level\": \"3\",\r\n    \"alias\": \"SH\"\r\n  },\r\n  {\r\n    \"city\": \"Chongqing\",\r\n    \"level\": \"3\",\r\n    \"alias\": \"CQ\"\r\n  },\r\n  {\r\n    \"city\": \"Jinan\",\r\n    \"level\": \"4\",\r\n    \"alias\": \"JN\"\r\n  }\r\n]\r\n```\r\n3. fix bug: if there are no new empty line(`\\n`) at the end of the file, may cause confusion.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimoer96%2Fcsv2json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimoer96%2Fcsv2json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimoer96%2Fcsv2json/lists"}