0
var csvToJson = require('convert-csv-to-json');
var fileInputName = 'Bangalore_schools.csv'; 
var fileOutputName = 'output.json';
csvToJson.generateJsonFileFromCsv(fileInputName, fileOutputName);

Csv File Link: Csv File

But the above code i have used i am unable to fully convert it to json. Please help. Output is coming like this.. i want to separate each key and its value likewise we have in 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)"
 }, 
  • Possible duplicate of [How to convert CSV to JSON in Node.js](https://stackoverflow.com/questions/16831250/how-to-convert-csv-to-json-in-node-js) – Satish Saini Mar 03 '19 at 08:42
  • *"As default the filed [sic] delimiter is the **semicolon** (`;`)."* You should read the docs for the library you're using. I'd also consider looking for a more mature library if you're going to rely on it for app functionality. – jonrsharpe Mar 03 '19 at 08:46

1 Answers1

0

The default delimiter convert-csv-to-json uses is a semicolon (;). If you want to use a different delimiter, like | the file you shared uses, you need to define it explicitly. E.g.:

csvToJson.fieldDelimiter('|').generateJsonFileFromCsv(fileInputName, fileOutputName);
Mureinik
  • 297,002
  • 52
  • 306
  • 350