@aws-lambda-powertools/jmespath
Version:
A type safe and modern jmespath module to parse and extract data from JSON documents using JMESPath
33 lines (32 loc) • 1.03 kB
JavaScript
import { ArityError, JMESPathTypeError, UnknownFunctionError, VariadicArityError, } from './errors.js';
import { TreeInterpreter } from './TreeInterpreter.js';
class ParsedResult {
expression;
parsed;
constructor(expression, parsed) {
this.expression = expression;
this.parsed = parsed;
}
/**
* Perform a JMESPath search on a JSON value.
*
* @param value - The JSON value to search
* @param options - The parsing options to use
*/
search(value, options) {
const interpreter = new TreeInterpreter(options);
try {
return interpreter.visit(this.parsed, value);
}
catch (error) {
if (error instanceof JMESPathTypeError ||
error instanceof UnknownFunctionError ||
error instanceof ArityError ||
error instanceof VariadicArityError) {
error.setExpression(this.expression);
}
throw error;
}
}
}
export { ParsedResult };