UNPKG

@aws-lambda-powertools/jmespath

Version:

A type safe and modern jmespath module to parse and extract data from JSON documents using JMESPath

36 lines (35 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParsedResult = void 0; const TreeInterpreter_js_1 = require("./TreeInterpreter.js"); const errors_js_1 = require("./errors.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_js_1.TreeInterpreter(options); try { return interpreter.visit(this.parsed, value); } catch (error) { if (error instanceof errors_js_1.JMESPathTypeError || error instanceof errors_js_1.UnknownFunctionError || error instanceof errors_js_1.ArityError || error instanceof errors_js_1.VariadicArityError) { error.setExpression(this.expression); } throw error; } } } exports.ParsedResult = ParsedResult;