maybeParseJson static method

dynamic maybeParseJson(
  1. dynamic value
)

Parses the dynamic value in to it's JSON decoded form. If the value cannot be decoded this will either return null.

Implementation

static dynamic maybeParseJson(dynamic value) {
  var result = value;

  try {
    if (value is Map) {
      result = Map<String, dynamic>.from(value);
    } else if (value is String) {
      result = json.decode(value);
    }
  } catch (e, stack) {
    _logger.severe(
      'Error parsing value: [$value]',
      e,
      stack,
    );
  }

  return result;
}