const JSONtoCSV = (arr: Array<object>, columns: string[], delimiter = ',') =>
[
columns.join(delimiter),
...arr.map(obj =>
columns.reduce(
(acc, key) =>
`${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
''
)
),
].join('\n');
Convert JSON to CSV
0
0
Giovanny Gongora
Converts an array of objects to a comma-separated values (CSV) string that contains only the columns specified.
0 Comments
Add Comment
Log in to add a comment