Answers for "convert json to csv npm"

90

csv to json npm

// Install
npm i csvtojson

// From CSV File to JSON Array
/** csv file
a,b,c
1,2,3
4,5,6
*/
const csvFilePath='<path to csv file>'
const csv=require('csvtojson')
csv()
.fromFile(csvFilePath)
.then((jsonObj)=>{
    console.log(jsonObj);
    /**
     * [
     * 	{a:"1", b:"2", c:"3"},
     * 	{a:"4", b:"5". c:"6"}
     * ]
     */ 
})
Posted by: Guest on June-15-2021
-1

convert json to csv npm

const { Parser } = require('json2csv'); const fields = ['field1', 'field2', 'field3'];const opts = { fields }; try {  const parser = new Parser(opts);  const csv = parser.parse(myData);  console.log(csv);} catch (err) {  console.error(err);}
Posted by: Guest on May-04-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language