getNested static method

dynamic getNested(
  1. Map<String, dynamic> json,
  2. List<String> path
)

Safely retrieves a nested property from a Map.

Example:

final value = FormioUtils.getNested(json, ['data', 'email']);

Returns null if any key is missing along the path.

Implementation

static dynamic getNested(Map<String, dynamic> json, List<String> path) {
  dynamic result = json;
  for (final key in path) {
    if (result is Map<String, dynamic> && result.containsKey(key)) {
      result = result[key];
    } else {
      return null;
    }
  }
  return result;
}