Categories
JavaScript Answers

How to convert CSV to JSON in Node.js?

Spread the love

To convert CSV to JSON in Node.js, we use the csvtojson module.

We install it by running

npm install --save csvtojson@latest

Then we use it by writing

const csv = require("csvtojson");

const jsonArrayObj = await csv().fromFile(csvFilePath);
console.log(jsonArrayObj);

to call fromFile to read the csv file into an JSON array.

Then we use await to get the JSON array of objects from the returned promise.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *