json<T> method
The file at path, decoded from JSON.
For a model type, the JSON goes through modelDecoders, or your app's
model decoders when null, the same as NyStorage.read<T>():
await disk().json<List<Order>>('orders.json').
Implementation
Future<T?> json<T>(String path, {Map<Type, dynamic>? modelDecoders}) async {
final String text = await get(path);
final dynamic data;
try {
data = jsonDecode(text);
} on FormatException catch (error) {
throw DiskException(
'The file is not valid JSON',
disk: name,
path: path,
cause: error,
);
}
if (data == null) return null;
if (T == dynamic || data is T) return data as T;
return dataToModel<T>(data: data, modelDecoders: modelDecoders);
}