@aws-lambda-powertools/jmespath
Version:
A type safe and modern jmespath module to parse and extract data from JSON documents using JMESPath
23 lines (22 loc) • 613 B
JavaScript
/**
* Apply a JMESPath expression to a JSON value.
*/
class Expression {
#expression;
#interpreter;
constructor(expression, interpreter) {
this.#expression = expression;
this.#interpreter = interpreter;
}
/**
* Evaluate the expression against a JSON value.
*
* @param value The JSON value to apply the expression to.
* @param node The node to visit.
* @returns The result of applying the expression to the value.
*/
visit(value, node) {
return this.#interpreter.visit(node ?? this.#expression, value);
}
}
export { Expression };