Search for data in a JSON object using a JMESPath expression.
import { search } from '@aws-lambda-powertools/jmespath';const data = { foo: { bar: { baz: 1 } }};const result = search('foo.bar.baz', data);console.log(result); // 1 Copy
import { search } from '@aws-lambda-powertools/jmespath';const data = { foo: { bar: { baz: 1 } }};const result = search('foo.bar.baz', data);console.log(result); // 1
By default the search function will use all the built-in functions present in the JMESPath specification.
Powertools for AWS Lambda provides some additional functions that can be used by passing them in the customFunctions option.
customFunctions
import { search } from '@aws-lambda-powertools/jmespath';import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';const data = { body: "{\"foo\": \"bar\"}"};const result = search( 'powertools_json(body)', data, { customFunctions: new PowertoolsFunctions() });console.log(result); // { foo: 'bar' } Copy
import { search } from '@aws-lambda-powertools/jmespath';import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';const data = { body: "{\"foo\": \"bar\"}"};const result = search( 'powertools_json(body)', data, { customFunctions: new PowertoolsFunctions() });console.log(result); // { foo: 'bar' }
The JMESPath expression to use
The JSON object to search
Optional
The parsing options to use
Search for data in a JSON object using a JMESPath expression.
Example
By default the search function will use all the built-in functions present in the JMESPath specification.
Powertools for AWS Lambda provides some additional functions that can be used by passing them in the
customFunctions
option.Example