jmespath

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

Package jmespath evaluates JSON queries with optional Powertools functions.

Index

Constants

View Source
const (
	APIGatewayREST            = "powertools_json(body)"
	APIGatewayHTTP            = "powertools_json(body)"
	SQS                       = "Records[*].powertools_json(body)"
	SNS                       = "Records[0].Sns.Message | powertools_json(@)"
	EventBridge               = "detail"
	CloudWatchEventsScheduled = "detail"
	KinesisDataStream         = "Records[*].kinesis.powertools_json(powertools_base64(data))"
	CloudWatchLogs            = "awslogs.powertools_base64_gzip(data) | powertools_json(@).logEvents[*]"
	S3SNSSQS                  = "Records[*].powertools_json(body).powertools_json(Message).Records[0]"
	S3SQS                     = "Records[*].powertools_json(body).Records[0]"
	S3SNSKinesisFirehose      = "records[*].powertools_json(powertools_base64(data)).powertools_json(Message).Records[0]"
	S3KinesisFirehose         = "records[*].powertools_json(powertools_base64(data)).Records[0]"
	S3EventBridgeSQS          = "Records[*].powertools_json(body).detail"
)

Built-in envelopes match all thirteen constants in TypeScript v2.35.0.

Variables

This section is empty.

Functions

func ExtractDataFromEnvelope

func ExtractDataFromEnvelope(data any, envelope string, options ...Option) (any, error)

ExtractDataFromEnvelope enables Powertools functions when options are omitted. Explicit options replace that default, following the reference helper.

func PurgeCache

func PurgeCache()

PurgeCache removes cached syntax trees; already compiled expressions remain valid.

func Search(source string, data any, options ...Option) (any, error)

Types

type Argument

type Argument struct {
	Types    []Type
	Variadic bool
}

Argument accepts any listed type. Only the final argument may be variadic.

type Error

type Error struct {
	Kind       ErrorKind
	Expression string
	Function   string
	Err        error
}

Error preserves expression context and the original failure through Unwrap.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorKind

type ErrorKind string

ErrorKind classifies failures without relying on engine error text.

const (
	EmptyExpression ErrorKind = "empty-expression"
	SyntaxError     ErrorKind = "syntax"
	UnknownFunction ErrorKind = "unknown-function"
	InvalidArity    ErrorKind = "invalid-arity"
	InvalidType     ErrorKind = "invalid-type"
	InvalidValue    ErrorKind = "invalid-value"
)

type Expression

type Expression struct {
	// contains filtered or unexported fields
}

Expression is immutable and reusable across goroutines. Custom functions must be concurrency-safe and must not mutate or retain their input values.

func Compile

func Compile(source string, options ...Option) (*Expression, error)

Compile prepares an expression. Standard functions are enabled by default; use WithPowertoolsFunctions for JSON, Base64 and gzip decoding.

func MustCompile

func MustCompile(source string, options ...Option) *Expression

func (*Expression) Search

func (e *Expression) Search(data any) (any, error)

Search accepts JSON-shaped values and typed Go events with JSON field tags. Data is normalized to a private JSON snapshot; numbers use float64 as in JS.

type ExpressionReference

type ExpressionReference = engine.ExpRef

type Function

type Function struct {
	Name      string
	Arguments []Argument
	Handler   func([]any) (any, error)
}

type Option

type Option func(functionTable) error

func WithFunctions

func WithFunctions(functions ...Function) Option

WithFunctions snapshots definitions and allows overriding built-in functions.

func WithPowertoolsFunctions

func WithPowertoolsFunctions() Option

WithPowertoolsFunctions enables the reference JSON, Base64 and gzip functions. Gzip inputs are fully buffered, matching the reference; bound untrusted inputs at the application boundary. Base64 uses Commons validation before decoding.

type Type

type Type = engine.JpType
const (
	Number      Type = engine.JpNumber
	String      Type = engine.JpString
	Array       Type = engine.JpArray
	Object      Type = engine.JpObject
	ArrayNumber Type = engine.JpArrayNumber
	ArrayString Type = engine.JpArrayString
	Expref      Type = engine.JpExpref
	Any         Type = engine.JpAny
	Boolean     Type = "boolean"
	Null        Type = "null"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL