{"id":13465505,"url":"https://github.com/Nero5023/CSVParser","last_synced_at":"2025-03-25T16:32:02.007Z","repository":{"id":11329474,"uuid":"69319618","full_name":"Nero5023/CSVParser","owner":"Nero5023","description":"A swift package for read and write CSV file","archived":false,"fork":false,"pushed_at":"2019-05-16T09:46:32.000Z","size":81,"stargazers_count":85,"open_issues_count":7,"forks_count":12,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-07-31T15:01:32.230Z","etag":null,"topics":["csv-parser","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/Nero5023.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":"2016-09-27T04:35:43.000Z","updated_at":"2024-07-10T10:11:37.000Z","dependencies_parsed_at":"2022-11-28T10:34:22.272Z","dependency_job_id":null,"html_url":"https://github.com/Nero5023/CSVParser","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nero5023%2FCSVParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nero5023%2FCSVParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nero5023%2FCSVParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nero5023%2FCSVParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nero5023","download_url":"https://codeload.github.com/Nero5023/CSVParser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222088563,"owners_count":16928977,"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-parser","swift"],"created_at":"2024-07-31T15:00:31.331Z","updated_at":"2024-10-29T17:31:05.607Z","avatar_url":"https://github.com/Nero5023.png","language":"Swift","funding_links":[],"categories":["Libs","Data Management [🔝](#readme)","Data and Storage"],"sub_categories":["Data Management"],"readme":"# CSVParser\nA swift library for fast read and write CSV file. This library supports all Apple platform and **Linux**.\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Plafrom](https://img.shields.io/badge/platform-linux%20%7C%20ios%20%7C%20osx%20%7C%20tvos%20%7C%20watchos%20-lightgray.svg)](https://github.com/Nero5023/CSVParser)\n\n## List to do\n---\n- [x] get column by string subscript\n- [x] error\n- [x] initialization from string\n- [x] Convert JSON To CSV\n- [x] Convert CSV To JSON\n- [ ] Concurrent parse\n## Requirements\n---\n\n* Swift 4.0+\n\n## Installation\n---\n### Swift Package Manager(Support Ubuntu)\n**If you want to use this package on Ubuntu, you shounld install with Swift Package Manager**\n\nIn `Package.swift` file\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n  name: \"YourProject\",\n  dependencies: [\n    .Package(url: \"https://github.com/Nero5023/CSVParser\",\n        majorVersion: 1),\n    ]\n)\n```\n\nRun command\n\n```bash\n$ swift build\n```\n\n### Carthage\n\nTo integrate CSVParser into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n\n\tgithub \"Nero5023/CSVParser\" ~\u003e 2.0.0\n\nRun `carthage update` to build the framework and drag the built `CSVParser.framework` into your Xcode project.\n\n\n\n## Usage\n\n###  Initialization \n\n```swift\nlet csv = try CSVParser(filePath: \"path/to/csvfile\")\n\n//catch error\ndo {\n\tlet csv = try CSVParser(filePath: \"path/to/csvfile\")\n}catch {\n\t// Error handing\n}\n\n// Custom delimiter\ndo {\n\tlet csv = try CSVParser(filePath: \"path/to/csvfile\", delimiter: \";\")\n}catch {\n\t// Error handing\n}\n\n// init from elements\nlet csv = try CSVParser(elements: [[\"a\", \"b\", \"c\"], [\"1\", \"2\", \"3\"]])\n```\n\n### Read data\n\n```swift\ndo {\n\tlet csv = try CSVParser(filePath: \"path/to/csvfile\")\n\t// get every row in csv\n\tfor row in csv {\n        print(row) // [\"first column\", \"sceond column\", \"third column\"]\n    }\n    \n    // get row by int subscript \n    csv[10] // the No.10 row\n    \n    // get column by string subscript\n    csv[\"id\"] // column with header key \"id\" \n\t\n}catch {\n\t// Error handing\n}\n\n```\n\n### Write data\n\n```swift\ndo {\n\tlet csv = try CSVParser(filePath: \"path/to/csvfile\")\n\t// get every row in csv\n\tcsv[0] = [\"test0\", \"test1\", \"test2\"]\n\tcsv.wirite(toFilePath: \"path/to/destination/file\")\n\t\n}catch {\n\t// Error handing\n}\n\n```\n\n### Subscript\n\n```swift\n// get row by int subscript \ncsv[10] // the No.10 row\n    \n// get column by string subscript\ncsv[\"id\"] // column with header key \"id\" \n\n```\n\n### Get dictionary elements\n\n```swift\nfor dic in csv.enumeratedWithDic() {\n\tprint(dic) // dic is [String: String]\t\n}\n\n```\n\n### CSV to JSON\nThe result json type is `[{\"header0\": \"a\",\"header1\": \"b\"},{\"header0\": \"a\", \"header1\": \"b\"}]`\n\n```swift\ndo {\n\tlet jsonStr = try csv.toJSON()\n}catch {\n\t// Error handing\n} \n\n```\n\n### JSON to CSV string\nNow only support this json type `[{\"header0\": \"a\",\"header1\": \"b\"},{\"header0\": \"a\", \"header1\": \"b\"}]`\n\n\n```swift\ndo {\n\tlet csvString = try CSVParser.jsonToCSVString(jsonData: jsonData) // jsonData is the Data type ot json\n}catch {\n\t// Error handing\n} \n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNero5023%2FCSVParser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNero5023%2FCSVParser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNero5023%2FCSVParser/lists"}