CSV TO JSON Conversion using Javascript Use the below code and then use command "node filename.js", this would generate a JSO...

CSV TO JSON Conversion



CSV TO JSON Conversion using Javascript

Use the below code and then use command "node filename.js", this would generate a JSON file which is converted from CSV.

Install this library  before using the below script
npm i --save csvtojson

const csvtojson = require('csvtojson')

const fs = require('fs')

 

const csvfilepath = "./CustomerData.csv"

 

csvtojson()

.fromFile(csvfilepath)

.then((json=> {

    console.log(json)

 

    fs.writeFileSync("./cypress/fixtures/output.json",JSON.stringify(json),"utf-8",(err=> {

        if(err) console.log(err)

    })

})

 

0 comments: