parseJsonPath function

JsonValue parseJsonPath(
  1. String jsonPath,
  2. JsonValue rootValue
)

Parses a JSON path expression and returns the corresponding value from the JSON.

Implementation

JsonValue parseJsonPath(String jsonPath, JsonValue rootValue) {
  if (jsonPath.isEmpty) {
    _log('JSON path is empty, returning root value', 'N/A', rootValue);
    return rootValue;
  }

  if (jsonPath[0] != r'$') {
    throw const FormatException(r'JSON path must start with "$"');
  }

  final result = parseExpression(jsonPath, 1, rootValue);
  _log('ParseExpression Result', '', result);
  return result;
}