jsonDecodeOrNone<T extends Object> function

Option<T> jsonDecodeOrNone<T extends Object>(
  1. dynamic input
)

Parses a JSON input into an object of type T, returning None on failure.

Supported types:

Implementation

Option<T> jsonDecodeOrNone<T extends Object>(dynamic input) {
  return letAsStringOrNone(input).map((rawInput) {
    try {
      final decoded = const JsonDecoder().convert(rawInput);
      return decoded is T ? Some<T>(decoded) : None<T>();
    } catch (e, _) {
      return None<T>();
    }
  }).flatten();
}