Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/export/export.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare function flattenObject(obj: object, separator: string): object;
declare function flatView(obj: object, separator?: string): object;

export {
flattenObject
flatView
};
28 changes: 8 additions & 20 deletions core/export/json/json.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
import {flatView} from '../export.service';

function updateTitles(rows, titles) {
const result = [];
for (let row of rows) {
const obj = {};
const values = Object.values(row);
for (let i = 0; i < titles.length; i++) {
obj[titles[i]] = values[i];
}
result.push(obj);
}
return JSON.stringify(result, '', 4);
}

export class Json {
write(rows, columns) {
const titles = [];
const result = [];

for (let row of rows) {
result.push(flatView(row));
}
for (let column of columns) {
titles.push(column.title);
const flatRow = flatView(row);
const obj = {};
for (let column of columns) {
obj[column.title] = flatRow[column.key];
}
result.push(obj);
}

return updateTitles(result, titles);
return JSON.stringify(result, '', 4);
}
}
}