2017-09-16 2 views
0

Große Bibliothek zum Parsen von CSV-Dateien!Knoten csvtojson. Wo ist das Ergebnis?

Schnelle Frage: wo ist das Ergebnis JSON nach dem Parsen einer CSV-Datei gespeichert? Das Tutorial bei https://www.npmjs.com/package/csvtojson#library hat dieses Beispiel:

const csvFilePath='<path to csv file>' 

const csv=require('csvtojson') 
csv() 
.fromFile(csvFilePath) 
.on('json',(jsonObj)=>{ 
    // combine csv header row and csv line to a json object 
    // jsonObj.a ==> 1 or 4 
}) 
.on('done',(error)=>{ 
    console.log('end') 
}) 

Aber, sobald 'done' heißt ... wo ist mein Ergebnis json ?!

Ich habe das Objekt im Debugger untersucht und kann das Ergebnis nicht finden.

Vielen Dank im Voraus

Antwort

1

Nun ist die Dokumentation ein bisschen irreführend.

Ich habe es durch Zwicken der Code wie folgt arbeiten,

const csvFilePath='<path to csv file>' 
const csv=require('csvtojson') 

csv().fromFile(csvFilePath,function(err,result){ 

    if(err){ 
     console.log("An Error Has Occured"); 
     console.log(err); 
    } 

    var json = result; 
    console.log(json); 
}); 

hoffe, das hilft!

+0

Hum, wusste nicht vonFile hatte einen Rückruf, als es fertig war ... sah es nicht in der Dokumentation. Vielen Dank! – Nacho

+0

Ja .. Die Dokumentation ist irreführend .. –