parseJson static method

dynamic parseJson(
  1. dynamic value, [
  2. dynamic defaultValue
])

Parses the dynamic value in to it's JSON decoded form. If the value cannot be decoded this will either return the defaultValue, if not null, or return the value that was passed in if defaultValue is null.

Implementation

static dynamic parseJson(
  dynamic value, [
  dynamic defaultValue,
]) {
  final result = value;

  if (value is String) {
    try {
      value = json.decode(value);
    } catch (e) {
      value = defaultValue ?? value;
    }
  }

  return result;
}