parseWildcard function

JsonValue parseWildcard(
  1. String jsonPath,
  2. int index,
  3. JsonValue value
)

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();
  }
}