Firstly, I use the CSV-parser from Node.js
first this code:
const parse = require("csv-parse/lib/sync");
const fs = require("fs");
const filePath = req.file.path;
const csvContent = fs.readFileSync(filePath);
const records = parse(csvContent, {
columns: false,
skip_empty_lines: true,
skip_lines_with_error: true,
delimiter: ";"
});
Now I have the problem that equal columns names will not be parsed if column are true.. if columns are true the results in the console are:
const records = parse(csvContent, {
columns: true,
[ { Referenz: 'Beispielwert1',
Client: 'Beispielwert2',
Clienthauptgruppe: 'Beispielwert3',
Kontrahent: 'Beispielwert4',
Kontrahentenhauptgruppe: 'Beispielwert5',
Bank: 'Beispielwert6',
Back_to_Back: 'Beispielwert7',
Int_Ext: 'Beispielwert8',
Valuta: 'Beispielwert9',
Geschaeftsart: 'Beispielwert10',
Kauf_Verkauf: 'Beispielwert11',
Wrg: 'Beispielwert12',
Diff_In_Hauswaehrung: 'Beispielwert13,
Hauswaehrung: 'Beispielwert14',
Marktwert_NPV: 'Beispielwert5' },
{ Referenz: 'Beispielwert1',
Client: 'Beispielwert2',
Clienthauptgruppe: 'Beispielwert3',
Kontrahent: 'Beispielwert4',
Kontrahentenhauptgruppe: 'Beispielwert5',
Bank: 'Beispielwert6',
Back_to_Back: 'Beispielwert7',
Int_Ext: 'Beispielwert8',
Valuta: 'Beispielwert9',
Geschaeftsart: 'Beispielwert10',
Kauf_Verkauf: 'Beispielwert11',
Wrg: 'Beispielwert12',
Diff_In_Hauswaehrung: 'Beispielwert13,
Hauswaehrung: 'Beispielwert14',
Marktwert_NPV: 'Beispielwert5' }]
if columns are false the results in the console are:
const records = parse(csvContent, {
columns: false,
[ [ 'Referenz',
'Client',
'Clienthauptgruppe',
'Kontrahent',
'Kontrahentenhauptgruppe',
'Bank',
'Back_to_Back',
'Int_Ext',
'Valuta',
'Geschaeftsart',
'Kauf_Verkauf',
'Wrg',
'Diff_In_Hauswaehrung',
'Hauswaehrung',
'Marktwert_NPV'
'Wrg'],
[ 'Beispielwert1',
'Beispielwert2',
'Beispielwert3',
'Beispielwert4',
'Beispielwert5',
'Beispielwert6',
'Beispielwert7',
'Beispielwert8',
'Beispielwert9',
'Beispielwert10',
'Beispielwert11',
'Beispielwert12',
'Beispielwert13',
'Beispielwert14',
'Beispielwert15'
'Beispielwert16' ],
[ 'Beispielwert1',
'Beispielwert2',
'Beispielwert3',
'Beispielwert4',
'Beispielwert5',
'Beispielwert6',
'Beispielwert7',
'Beispielwert8',
'Beispielwert9',
'Beispielwert10',
'Beispielwert11',
'Beispielwert12',
'Beispielwert13',
'Beispielwert14',
'Beispielwert15'
'Beispielwert16' ]]
Here for example the column Wrg is the double column and if columns stands on: true.. it doesn't exist
Now I want the same form again as above mentioned if columns are true.. but how can I put multiple Arrays to one object if the multiple arrays are in one variable (records)?
Best regards
Frederic