var csvToJson = require('convert-csv-to-json');
var fileInputName = 'Bangalore_schools.csv';
var fileOutputName = 'output.json';
csvToJson.generateJsonFileFromCsv(fileInputName, fileOutputName);
Csv文件链接:Csv File
但是我使用的以上代码无法将其完全转换为json。请帮忙。输出是这样的..我想像我们在json中一样分离每个键及其值。
[
{
"district|block|cluster|schoolid|schoolname|category|gender|medium_of_inst|address|area|pincode|landmark|identification1|busroutes|identification2|latlong": "-----------+---------+----------------------------+----------+-------------------------------------------+---------------+--------+----------------+---------------------------------------------------------------------------------------------------------------+-----------------------------------------+------------------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-------------------------------------------+-----------------------------------------------------------------------------------------------------+------------------------------------------"
},
{
"district|block|cluster|schoolid|schoolname|category|gender|medium_of_inst|address|area|pincode|landmark|identification1|busroutes|identification2|latlong": " bangalore|south-1|vajara halli|32868|GKHPS ALAHALLI|Upper Primary|co-ed|kannada|avalahalli south range- 1|bangalore|560062|masjid||||POINT(77.5766623020172 12.8893003120716)"
},
答案 0 :(得分:0)
convert-csv-to-json
使用的默认定界符是分号(;
)。如果要使用其他定界符(例如|
共享使用的文件),则需要显式定义它。例如:
csvToJson.fieldDelimiter('|').generateJsonFileFromCsv(fileInputName, fileOutputName);