Answers for "csv to json nodejs"

2

nodejs csv to json from link

// npm install --save csvtojson@latest
const csv = require("csvtojson");
const request = require('request');
// Convert a csv file with csvtojson
csv().fromStream(request.get('https://fileas.csv))
  	.then(function(jsonArrayObj){
  		//when parse finished, result will be emitted here.
    	console.log(jsonArrayObj); 
 	})
Posted by: Guest on July-22-2021
90

csv to json nodejs

// 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
0

json to csv nodejs

const { Parser } = require('json2csv');

const myCars = [
  {
    "car": "Audi",
    "price": 40000,
    "color": "blue"
  }, {
    "car": "BMW",
    "price": 35000,
    "color": "black"
  }, {
    "car": "Porsche",
    "price": 60000,
    "color": "green"
  }
];

const json2csvParser = new Parser();
const csv = json2csvParser.parse(myCars);

console.log(csv);
Posted by: Guest on June-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language