req<T> function
Reads a required key of type T, throwing with the JSON path if absent
or of the wrong type.
dart:convert decodes a JSON whole number (e.g. 2) as int, never
double. Read numeric fields as num or int — T = double will throw
on a valid whole-number value.
Implementation
T req<T>(Map<String, dynamic> json, String key, String path) {
final value = json[key];
if (value is T) return value;
throw SchemaFormatException(
_join(path, key),
'expected $T, got ${value.runtimeType}',
);
}