object function
Reads an optional sub-object. Absent reads as null; present but not an
object throws.
This is deliberately stricter than opt. opt's licence covers a scalar
widening — an older client reading a field the server changed the shape of.
A whole container arriving as a scalar is a server bug, and reading it as
absent turns it into a silently empty card or a deny-all permission set.
Implementation
Map<String, dynamic>? object(
Map<String, dynamic> json,
String key,
String path,
) {
final value = json[key];
if (value == null) return null;
if (value is! Map<String, dynamic>) {
throw SchemaFormatException(
_join(path, key),
'expected object, got ${value.runtimeType}',
);
}
return value;
}