2

I don't understand the documentation of Papaparse unparse config. The docs say on https://www.papaparse.com/docs#json-to-csv to unparse like this

Papa.unparse(data[, config])

So far I managed to generate a CSV with a header and write it to the file system. Yet I don't know how to change the delimeter e.g. to semicolon instead of the default comma.

This is where I am stuck:

const data = initial.map((obj) => [
    obj.id,
    obj.name
]);
const fields = ['id', 'name'];
const config = { delimiter: ';' };
const csv2Export = Papa.unparse({ data, fields }, { config });

I've tried playing around with the unparse method yet however I rearange the data and config objects, the delimeter remains a comma.

Any help is highly appreciated. Thanks in advance

SaHeinem
  • 358
  • 1
  • 3
  • 10

1 Answers1

1

Unparse directly takes data and config as parameters:

const data = initial.map((obj) => [
    obj.id,
    obj.name
]);
const config = { delimiter: ';' };
const csv2Export = Papa.unparse( data, config );