Documentation
¶
Overview ¶
Package jqfilter compiles a jq program (github.com/itchyny/gojq) and runs it over a stream of JSON documents to filter and/or transform them. It is the engine behind the monitor command's --jq flag.
Number fidelity is the load-bearing property. Korbit money/quantity values are decimal strings on the wire, and gojq passes strings through untouched. Numeric JSON values are decoded as json.Number (UseNumber) and gojq preserves json.Number verbatim for any operation that does not do arithmetic on that value (select/identity/field access/comparison) — so a pure filter never rounds a number through float64. Precision is lost only where the program itself does number math (tonumber, +, *, …), which is the caller's explicit choice. TestGojqPreservesJSONNumber pins this library behavior.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a compiled jq program. A compiled gojq.Code is stateless across runs, so a Program is safe to Run repeatedly.
func Compile ¶
Compile parses and compiles src. The returned error is user-facing — it names the jq syntax/compile problem — so a caller can surface it as a usage error.
func (*Program) Run ¶
Run executes the program against one input JSON document and returns the lines to emit, in order:
- Each value the program produces becomes one output line. A program that produces no values (e.g. select(false)) returns an empty slice — the document is filtered out.
- When an output value is deep-equal to the input (a select-style filter that passed, or identity), the ORIGINAL input bytes are returned verbatim — preserving exact decimal strings and the input's object key order. Only a transformed value is re-encoded by gojq (whose encoder is faithful to json.Number but sorts object keys).
A jq runtime error (e.g. tonumber on a non-numeric string) is returned with no output lines; the caller decides whether to skip the document (the monitor does, rate-limited, like a --where exception). A jq `halt`/`halt_error` ends output for this document without an error — the lines produced before it are returned. The context bounds a runaway program so Ctrl-C / --duration can interrupt it.
The verbatim line returned for a passing filter ALIASES input — it is not copied. Callers must emit it before reusing the input buffer.