parseWildcard function
Parses a JSON path expression with a wildcard and returns the corresponding
Implementation
JsonValue parseWildcard(String jsonPath, int index, JsonValue value) {
_log('Parsing wildcard', jsonPath.substring(0, index), value);
if (value is JsonObject) {
final values = value.fields
.map((field) => parseExpression(jsonPath, index, value.getValue(field)))
.toList();
return JsonArray(values);
} else if (value is JsonArray) {
final values = value.value
.map((item) => parseExpression(jsonPath, index, item))
.toList();
return JsonArray(values);
} else if (value is Undefined) {
_log(
'Value is Undefined, returning Undefined',
jsonPath.substring(0, index),
value,
);
return const Undefined();
} else {
_log(
'Value is not an object or array, returning Undefined',
jsonPath.substring(0, index),
value,
);
return const Undefined();
}
}