json-from-csv
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

CSV to JSON Converter

Description

This Node.js module provides a function to convert CSV (Comma-Separated Values) files to JSON (JavaScript Object Notation) format. The function reads the CSV file, parses its contents, and returns a JSON array representing the data.

Installation

To use this module, install it via npm:

npm i json-from-csv

Example

const { csvToJson } = require('json-from-csv');

// Path to your CSV file
const csvFilePath = 'sample_2.csv';

// If you want to use a separator other than ",", you can specify it here like this: const separator = ";" etc
const separator = ";"

// Call the csvToJson function with the path to your CSV file and optional separator
csvToJson(csvFilePath)
  .then(jsonData => {
    // Do whatever you want with the JSON data here
    console.log("Converted JSON data:",jsonData);
  })
  .catch(error => {
    // Handle any errors that occur during conversion
    console.error("An error occurred:", error);
  });

Code Format

When calling the csvToJson function, provide the file path as the first parameter. If no separator is specified as the second parameter, it will default to a comma (,).

Note

  • The CSV file must have a '.csv' extension.
  • Empty rows in the CSV file are skipped during conversion.
  • Leading and trailing spaces in header names and data values are trimmed.

Video Tutorial

Check out our video tutorial on YouTube: here

Authors

@tahirabbas11

Contributing

  • Contributions are welcome! To contribute:
    • Fork the repository.
    • Make changes.
    • Submit a pull request (PR).

Click here to reach the repository, Please ensure your PR follows these steps.

Package Sidebar

Install

npm i json-from-csv

Weekly Downloads

15

Version

0.0.5

License

MIT

Unpacked Size

6.79 kB

Total Files

6

Last publish

Collaborators

  • tahirabbas11