当使用csv模块中的csv-parser将csv文件转换为json时,如何将头文件作为json输出中的密钥对?

问题描述 投票:1回答:1

我正在尝试类似下面的内容,但这不起作用

const parser = parse(req.file, {
  headers: true
})
// Use the readable stream api
parser.on('data', function(csvrow) {
  console.log(csvrow);
})
javascript npm
1个回答
0
投票

这对我有用

parse(sampleFile, {columns: true}, function(err, data){
        console.log(JSON.stringify(data,null,2));
    });
© www.soinside.com 2019 - 2024. All rights reserved.