toBoolJson static method

bool? toBoolJson(
  1. dynamic json, {
  2. bool isCaseSensitive = true,
})

Converts JSON to a boolean.

Implementation

static bool? toBoolJson(dynamic json, {bool isCaseSensitive = true}) {
  if (json == null) return null;
  if (json is bool) return json;
  if (json is int) return json == 1;
  final String str = json.toString();
  return str == '1' || (isCaseSensitive ? str == 'true' : str.toLowerCase() == 'true');
}