fromJsonMapString static method

Map<String, Datacat> fromJsonMapString(
  1. String jsonString
)

Creates nested Datacats from a JSON string representing a map, where each key maps to a list of objects. Returns a Map<String, Datacat>.

Implementation

static Map<String, 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 result;
}