jqtransform

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package jqtransform runs operator-supplied jq expressions against the JSON form of builder objects (execution payloads, bids, envelopes) so builders can apply arbitrary custom modifications the tool is not aware of. It wraps the pure-Go gojq interpreter (no I/O, context-cancellable) with a strict single-output contract and environment access disabled.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty = errors.New("jq expression produced no output")

ErrEmpty is returned when an expression produces no output (e.g. `empty` or a filter that selects nothing) — a transform must yield exactly one object.

View Source
var ErrMultiple = errors.New("jq expression produced multiple outputs")

ErrMultiple is returned when an expression produces more than one output — a transform must yield exactly one object.

Functions

func Apply

func Apply(ctx context.Context, expr string, inputJSON []byte) ([]byte, error)

Apply runs the expression against inputJSON (any JSON value) and returns the single transformed value marshaled back to JSON. An empty expression returns inputJSON unchanged. The context bounds execution time; a runaway expression (e.g. an unbounded generator) is cut off when ctx is cancelled.

func ApplyTyped

func ApplyTyped[T JSONObject](ctx context.Context, expr string, src, dst T) error

ApplyTyped applies the expression to src's JSON form and decodes the result into dst. dst must be constructed with the correct Version already set (the union types select their JSON view from Version). An empty expression copies src into dst unchanged. On any error dst is left partially written and must be discarded by the caller.

func Validate

func Validate(expr string) error

Validate parses and compiles the expression, returning a descriptive error when it is not a valid jq program. Empty expressions are valid (no-op).

Types

type JSONObject

type JSONObject interface {
	json.Marshaler
	json.Unmarshaler
}

JSONObject is a value that can round-trip through JSON in both directions. The builder's fork-agnostic union types (execution payload, bid message, envelope message) satisfy it; their UnmarshalJSON requires the target's Version to be preset, so callers construct dst with the right Version.

Jump to

Keyboard shortcuts

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