npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@srihari_007/csv-to-json-converter

v1.1.0

Published

CSV to JSON converter is a lightweight and powerful utility that uses node.js to convert CSV files to JSON in an easy and customizable manner.

Downloads

13

Readme

CSV-TO-JSON

CSV to JSON converter is a lightweight and powerful utility that uses node.js to convert CSV files to JSON in an easy and customizable manner.

Installation

npm install @srihari_007/csv-to-json-converter

Usage

const csvtojson = require("@srihari_007/csv-to-json-converter");

// Convert a CSV file at the specified file path to a JSON object
const jsonFromFilePath = csvtojson().fromFilePath("/path/to/file.csv");

// Convert a CSV string to a JSON object
const jsonFromString = csvtojson().fromString(
  "header1,header2\nvalue1,value2\nvalue3,value4"
);

// Convert a CSV array to a JSON object
const jsonFromArray = csvtojson().fromArray([
  "header1,header2",
  "value1,value2",
  "value3,value4",
]);

// Convert a CSV two-dimensional array to a JSON object
const jsonFromTwoDArray = csvtojson().fromTwoDimensonArray([
  ["header1", "header2"],
  ["value1", "value2"],
  ["value3", "value4"],
]);

Error Handling

The csvtojson object has four methods: fromFilePath, fromString, fromArray, and fromTwoDimensonArray. If an error occurs while using one of these methods, an error will be thrown with a message indicating the cause of the error.

The possible error messages are:

  • Invalid file: The file specified by filePath is empty or contains only the headers.
  • Invalid path: The file specified by filePath does not exist.
  • Invalid file format: The file specified by filePath is not a CSV file.
  • Invalid syntax: The number of headers does not match the number of values in a row of the CSV file.

Notes

  • The fromFilePath method expects the file path to be specified as a string.
  • The fromString, fromArray, and fromTwoDimensonArray methods expect the CSV data to be in the form of a string, array, or two-dimensional array, respectively.
  • The first row of the CSV data is assumed to contain the headers.
  • The values in the JSON objects will be of the appropriate data type (e.g. numbers will be converted to numbers, True/False will be converted to boolean, strings will be left as strings).

Motivation

The reason for this tool is that I was in charge of converting a couple of csv files to JSON and I couldn't find anything simple that did exactly what I expected. So I built this to be flexible enough for any file.

Author

License

csv-to-json-converter is released under the MIT license.