Datacat.fromJsonMapString constructor
Datacat.fromJsonMapString(
- String jsonString
Creates nested Datacats from a JSON string representing a map where each key maps to a list of objects.
Implementation
factory Datacat.fromJsonMapString(String jsonString) {
final decoded = json.decode(jsonString);
if (decoded is! Map) {
throw ArgumentError(
'JSON input must be a map with keys mapping to lists.');
}
final result = <String, Datacat>{};
decoded.forEach((key, value) {
if (value is List) {
result[key.toString()] = Datacat.fromJsonString(json.encode(value));
} else {
throw ArgumentError('Value for key "$key" must be a list.');
}
});
// Return a Datacat whose columns are the keys (names of nested tables)
// and no rows. Adjust as needed.
return Datacat(columns: result.keys.toList(), rows: []);
}