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

csv-json-convertor

v2.0.0

Published

A simple csv-json convertor

Downloads

6

Readme

Converter banner

npm (tag) npm GitHub last commit licence

Overview

Csv-json-convertor, as its name implies, is a simple csv-json conversion tool. You can use it to easily convert csv files to json objects and/or files, as well as the other way around (convert json files to csv).

Installation

Install via npm: npm install csv-json-convertor NPM

Usage

After installing, import and use in your project as follows:

CSV to JSON

// require destructured toJSON function
const { toJSON } = require('csv-json-convertor');

// convert csv file
toJSON('path/to/csvFile.csv', api => {
    // log or use object (result from the conversion)
    console.log(api.data); 
    // save new .json file (./csvFile.json by default) to current directory
    api.save() 
});

You can specify save options such as filename, prettify and spaces as in the following examples By default: filename: name of the csv file prettify: false spaces: 1

// filename
toJSON('path/to/csvFile.csv', api => {
    const options = {
        filename: newJsonFile
    };
    api.save(options); 
    // Output: newJsonfile.json, not prettified
}); 

// filename, prettify 
toJSON('path/to/csvFile.csv', api => {
    const options = {
        filename: newJsonFile,
        prettify: true
    };
    api.save(options); 
    // Output: newJsonFile.json, prettified using a spacing of 1
}); 

// filename, prettify, spaces
toJSON('path/to/csvFile.csv', api => {
    const options = {
        filename: `newJsonFile`,
        prettify: true,
        spaces: 2
    };
    api.save(options); 
    // Output: ./newJsonFile.json, prettified using a spacing of 2
}); 

Preview of conversion to json

JSON to CSV

The toCSV method is quite the opposite of toJSON

// require destructured toCSV function
const { toCSV } = require('csv-json-convertor');

// convert csv file
toCSV('path/to/jsonFile.json', api => {
    // log or use string (result from the conversion)
    console.log(api.data);
    // save new .csv file (./jsonFile.csv by default) to current directory 
    api.save();
});

The save method accepts an options object which currently contains just one property, filename, with which you can specify the name of the new file to be saved.

// filename
toJSON('path/to/jsonFile.json', api => {
    const options = {
        filename: `newCsvFile`
    };
    api.save(options); 
    // Output: ./newCsvFile.csv
}); 

Contributing

I need help with writing a good documentation for this project. Also, any ideas or suggestions on new features, enhancements and performance improvement are very welcome. Feel free to contribute in anyway you can.