query

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package query wraps gojq: it compiles a jq expression once and runs it over decoded record values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromJSON

func FromJSON(raw []byte) (any, error)

FromJSON prepares raw JSON for querying, keeping numbers as json.Number so long packed-decimal values do not lose precision on the way in.

func Marshal added in v0.2.0

func Marshal(v any) string

Marshal renders one query output as compact JSON in jq's own encoding.

Types

type Halt

type Halt struct {
	Value    any // non-nil for halt_error: the error payload
	ExitCode int
}

Halt is returned by Run when the expression called halt or halt_error; processing of further input should stop.

func (*Halt) Error

func (h *Halt) Error() string

type Query

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

Query is a compiled jq expression.

func Compile

func Compile(expr string) (*Query, error)

Compile parses and compiles a jq expression.

func (*Query) Run

func (q *Query) Run(v any, emit func(any) error) error

Run evaluates the query against one input value and calls emit for each result. Errors raised by the expression (including halt) abort the run.

func (*Query) RunContext added in v0.2.0

func (q *Query) RunContext(ctx context.Context, v any, emit func(any) error) error

RunContext evaluates like Run but honors ctx, so interactive callers can bound a pathological expression instead of freezing.

Jump to

Keyboard shortcuts

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