Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/its-just-nans/csv-to-custom-json
Easily transform your CSV to a custom JSON with cool options
https://github.com/its-just-nans/csv-to-custom-json
csv csv-parser csv-to-json csvtojson custom-json json nodejs
Last synced: 8 days ago
JSON representation
Easily transform your CSV to a custom JSON with cool options
- Host: GitHub
- URL: https://github.com/its-just-nans/csv-to-custom-json
- Owner: Its-Just-Nans
- License: mit
- Created: 2021-06-01T11:29:46.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-29T19:25:34.000Z (about 1 month ago)
- Last Synced: 2024-12-29T20:24:43.436Z (about 1 month ago)
- Topics: csv, csv-parser, csv-to-json, csvtojson, custom-json, json, nodejs
- Language: JavaScript
- Homepage: https://its-just-nans.github.io/csv-to-custom-json-demo/
- Size: 93.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# csv-to-custom-json ยท [![npm version](https://img.shields.io/npm/v/csv-to-custom-json.svg)](https://www.npmjs.org/package/csv-to-custom-json)
- - demo
- - npm
- - python versionTransform your `.csv` file to a **custom** JSON structure :) ! In browser and NodeJS !
Click to expand
- [csv-to-custom-json ยท ](#csv-to-custom-json--)
- [Simple documentation](#simple-documentation)
- [Simple case](#simple-case)
- [Structure JSON](#structure-json)
- [Options](#options)
- [Documentation](#documentation)
- [Examples](#examples)
- [Issues](#issues)
- [About](#about)
- [License](#license)## Simple documentation
### Simple case
You just want to parse your `.csv` without structure :
```javascript
const parseFile = require("csv-to-custom-json");
const parsed = await parseFile(linkFile);
```### Structure JSON
First you need to create the schema of your future JSON
```javascript
const schema = {
num1: "int",
num2: "float",
num3: "string",
num4 (value, allValues) {
// this is a callBack !
},
async num5 (value, allValues) {
// this is a async callBack !
}
};
// then
const parsedFile = await parseFile("myfile.csv", schema);
```> Legend :
>
> - `num1`, `num2`, `num3`, `num4`, `num5` are rows from the `.csv`
> - You can see that the value of attribute define how variable will be parse
> - You can see that we can use callBack, the value returned by the callBack will be put in the result (if not `undefined` or `null`)This program allow you to create complex structured JSON, like this :
```javascript
const schema = {
hello: [
{
num4: "int",
num1: "string"
}
],
hello2: [
{
num4: "int",
num1: [
{
num3: "string"
}
]
}
]
};
// then
const parsedFile = await parseFile("myfile.csv", schema);
```### Options
To use options, you need to add a third parameters which is an object with options.
Example :
```javascript
const parsedFile = await parseFile("myfile.csv", schema, {
debug: true,
});
```All options are listed in the documentation (you can run [examples](#examples) to help you) !
## Documentation
A whole documentation is available on [./docs](./docs)
## Examples
To see examples, you can do :
```sh
npm run test
```And see `*.test.js` files to know which code is used !
## Issues
Oh no ๐ !
Go here [csv-to-custom-json/issues](https://github.com/Its-Just-Nans/csv-to-custom-json/issues)
## About
I coded this instead of doing my homework ๐ณ
You can discuss here : [csv-to-custom-json/discussions](https://github.com/Its-Just-Nans/csv-to-custom-json/discussions)
## License
Licensed under the MIT License - [LICENSE](LICENSE)