parseToMaps static method
List<Map<String, dynamic> >
parseToMaps(
- String content, {
- List<
TCsvColumn> ? columns, - String? delimiter,
Parses any supported format (CSV, TSV, DSV, JSON) directly into typed Maps.
If columns schema is provided, applies auto-mapping and type coercion.
Implementation
static List<Map<String, dynamic>> parseToMaps(
String content, {
List<TCsvColumn>? columns,
String? delimiter,
}) {
final result = parseGeneric(content, delimiter: delimiter);
if (result.isEmpty) return [];
if (columns != null && columns.isNotEmpty) {
final mapping = TCsvHeaderMapping.autoMap(
expectedColumns: columns,
csvHeaders: result.headers,
);
return result.rows.map((row) {
return mapping.mapRow(
expectedColumns: columns,
csvHeaders: result.headers,
csvRow: row,
);
}).toList();
}
// No columns schema provided: return direct map from headers to row values
if (result.jsonMaps != null) {
return result.jsonMaps!;
}
return result.rows.map((row) {
final map = <String, dynamic>{};
for (int i = 0; i < result.headers.length; i++) {
final header = result.headers[i];
map[header] = i < row.length ? row[i] : null;
}
return map;
}).toList();
}