toJsonFromRows static method
Converts headers and rows to a formatted JSON string.
Implementation
static String toJsonFromRows(
List<String> headers,
List<List<dynamic>> rows, {
bool pretty = true,
List<TCsvColumn>? columns,
}) {
final maps = rows.map((row) {
final map = <String, dynamic>{};
for (int i = 0; i < headers.length; i++) {
final header = headers[i];
final val = i < row.length ? row[i] : null;
if (columns != null) {
final col = columns.firstWhere(
(c) => c.header == header || c.key == header,
orElse: () => TCsvColumn.text(key: header, header: header),
);
map[col.key] = col.parseValue(val);
} else {
map[header] = val;
}
}
return map;
}).toList();
return toJson(maps, pretty: pretty);
}