Socket
Socket
Sign inDemoInstall

csv-to-custom-json

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    csv-to-custom-json

Easily transform your CSV to a custom JSON with cool options


Version published
Maintainers
1
Created

Readme

Source

csv-to-custom-json

npm version

Transform your .csv file to a custom JSON structure :) !

Click to expand

Simple documentation

Simple case

You just want to parse your .csv without structure :

const parseFile = require("./index");
const parsed = await parseFile(linkFile);

Structure JSON

First you need to create the schema of your futur 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 strucured 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 paramters which is an object with options.

Example :

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

For options, when I say boolean, in reality, it can be any true value of javascript. Same for false.

Run examples to help you !

All options are listed in the documentation

Documentation

A whole documentation is available on GitHub : https://github.com/Its-Just-Nans/csv-to-custom-json/wiki

And if you really really like it, you can even clone it with :

git clone https://github.com/Its-Just-Nans/csv-to-custom-json.wiki.git

Legend :

  • Just "wow"

Examples

To see examples, you can do :

npm run test

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

About

I coded this instead of doing my homework 😳

License

Licensed under the MIT License - LICENSE

Keywords

FAQs

Last updated on 19 Jun 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc