parseJSON function

dynamic parseJSON(
  1. Object? json, [
  2. Object? def
])

Parses json to a JSON tree.

def The default value if json is null, empty or a blank String (of any length).

Implementation

dynamic parseJSON(Object? json, [Object? def]) {
  if (json == null) return def;

  if (json is String) {
    // `isBlankString` stops at the first non-blank char (cheap for a JSON).
    if (json.isEmpty || isBlankString(json)) return def;
    return dart_convert.json.decode(json);
  } else {
    return json;
  }
}