requireMap function

CrossmintJsonMap requireMap(
  1. CrossmintJsonMap map,
  2. String key, {
  3. required String entity,
})

Returns the nested JSON object at key in map, or throws a typed CrossmintDeserializationException naming entity and key.

Implementation

CrossmintJsonMap requireMap(
  CrossmintJsonMap map,
  String key, {
  required String entity,
}) {
  final Object? value = map[key];
  if (value is Map<String, Object?>) {
    return value;
  }
  throw CrossmintDeserializationException(
    'Expected JSON object for "$key" while parsing $entity.',
    entity: entity,
    field: key,
    cause: map,
  );
}