We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent afeaf49 commit 0362ec7Copy full SHA for 0362ec7
1 file changed
src/utils/ServiceUtils.ts
@@ -18,3 +18,19 @@ export function unflatten(obj: object) {
18
19
return result;
20
}
21
+
22
+export function jsonToCsv(data: Record<string, string>[]): string {
23
+ if (!Array.isArray(data) || !data.length) {
24
+ throw new Error('Input JSON array is empty');
25
+ }
26
27
+ const headers = Object.keys(data[0]);
28
+ const csvRows = [
29
+ headers.join(','),
30
+ ...data.map(row => headers.map(header =>
31
+ JSON.stringify(row[header] ?? '')).join(',')
32
+ ),
33
+ ];
34
35
+ return csvRows.join('\n');
36
+}
0 commit comments