parseDotNotation function

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

Parses a JSON path expression in dot notation and returns the corresponding

Implementation

JsonValue parseDotNotation(String jsonPath, int index, JsonValue value) {
  _log('Parsing dot notation', jsonPath.substring(0, index), value);
  if (index >= jsonPath.length) {
    // We've reached the end of the JSON path, so return the value
    _log(
      'Reached end of JSON path, returning value',
      jsonPath.substring(0, index),
      value,
    );
    return value;
  }

  if (value is! JsonObject) {
    _log(
      'Value is not a JsonObject, returning Undefined',
      jsonPath.substring(0, index),
      value,
    );
    return const Undefined();
  }

  if (jsonPath[index] == '*') {
    index++;
    return parseWildcard(jsonPath, index, value);
  }

  final fieldName = parseFieldName(jsonPath, index);
  index += fieldName.length;

  final fieldValue = value[fieldName];
  if (fieldValue != const Undefined()) {
    return parseExpression(jsonPath, index, fieldValue);
  } else {
    _log(
      'Field not found, returning Undefined',
      jsonPath.substring(0, index),
      value,
    );
    return const Undefined();
  }
}