getJsonField function
dynamic
getJsonField(
- dynamic response,
- String jsonPath, [
- bool isForList = false
])
Implementation
dynamic getJsonField(
dynamic response,
String jsonPath, [
bool isForList = false,
]) {
final field = JsonPath(jsonPath).read(response);
if (field.isEmpty) {
return null;
}
if (field.length > 1) {
return field.map((f) => f.value).toList();
}
final value = field.first.value;
if (isForList) {
return value is! Iterable
? [value]
: (value is List ? value : value.toList());
}
return value;
}