I found out that using npm csvtojson is much easier.
CSV:
email, contactNo, meta.0.key, meta.0.value, meta.0.type, meta.1.key, meta.1.value, meta.1.type
[email protected], 12345, Name, Kevin XYZ, string, Position, Chairman, string
[email protected], 321433, Name, John ABC, string, Position, Accountant, string
by using the following code:
const csv = require('csvtojson');
const csvStr = "The csv above"
csv()
.fromString(csvStr)
.subscribe((jsonObj) => {
console.log(jsonObj);
});
The result of the json will be:
{ email: '[email protected]',
contactNo: '12345',
meta:
[ { key: 'Name', value: 'Kevin XYZ', type: 'string' },
{ key: 'Position', value: 'Chairman', type: 'string' } ] }
{ email: '[email protected]',
contactNo: '321433',
meta:
[ { key: 'Name', value: 'John ABC', type: 'string' },
{ key: 'Position', value: 'Accountant', type: 'string' } ] }
In conclusion, using the header xx.0.yy is not so user friendly, I recommend just using what Duc Hong said.. header: email, contactNo, Name, Position and transform to the format that you want.