I am trying to load sample csv files into project read the content and display according to the filed. I done uploading and file writing but could not optimize the json structure properly for future use case
Here is my sample code :
let csvToJson = require('convert-csv-to-json');
let json = csvToJson.getJsonFromCsv(filepath);
var lines = [];
for(let i=0; i<json.length;i++){
console.log(json[i]);
lines.push(json[i])
}
console.log(lines);
var result3=JSON.stringify(lines);
result3 = result3.replace(/\r?\n|\r/g, " ");
console.log(result3);
My output:
console.log(json[i]) =
Object {name,age,address: "asd,20,"12/76, 11th cross"
"}
browser.js:5358 Object {name,age,address: "dff,30,"33, 11th cross"
"}
browser.js:5358 Object {name,age,address: "f,22,"7g/22, 12th cross"
"}
browser.js:5358 Object {name,age,address: "ghth,55,"4h, 13th cross"
"}
console.log(lines) = [Object, Object, Object, Object, Object]
console.log(result3)
[{"name,age,address":"asd,20,\"12/76, 11th cross\"\r"},
{"name,age,address":"dff,30,\"33, 11th cross\"\r"},
{"name,age,address":"f,22,\"7g/22, 12th cross\"\r"},
{"name,age,address":"ghth,55,\"4h, 13th cross\"\r"},
{"name,age,address":"fhg,44,\"6t, 10th cross\"\r"}]
My expected output:
{name:[],age:[],address:[]}
i.e I want all "name" values should store in the name key similar to "age" and "address". Can anybody help me how to do this?