1
0
Fork
You've already forked csv-to-custom-json
0
Easily transform your CSV to a custom JSON with cool options
  • JavaScript 94.2%
  • Svelte 4.8%
  • HTML 1%
2025年01月01日 19:12:26 +01:00
.github/workflows rm action 2025年01月01日 19:09:53 +01:00
csv-to-custom-json move demo into repo 2025年01月01日 19:06:27 +01:00
csv-to-custom-json-demo use relative to real demo 2025年01月01日 19:12:26 +01:00
LICENSE Create LICENSE 2021年06月12日 15:37:10 +02:00
README.md move demo into repo 2025年01月01日 19:06:27 +01:00

csv-to-custom-json · npm version

Transform your .csv file to a custom JSON structure :) ! In browser and NodeJS !

Click to expand

Simple documentation

Simple case

You just want to parse your .csv without structure :

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

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 :

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 :

const parsedFile = await parseFile("myfile.csv", schema, {
 debug: true,
});

All options are listed in the documentation (you can run examples to help you) !

Documentation

A whole documentation is available on ./docs

Examples

To see examples, you can do :

npm run test

And see *.test.js files to know which code is used !

Issues

Oh no 😟 !

Go here csv-to-custom-json/issues

About

I coded this instead of doing my homework 😳

You can discuss here : csv-to-custom-json/discussions

License

Licensed under the MIT License - LICENSE