Documentation
¶
Overview ¶
Package jq facilitates processing of JSON strings using jq expressions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Evaluate ¶
Evaluate runs a jq expression against the single JSON value in r and writes the results to w. Scalar results are written as raw strings (no quotes); objects and arrays are marshalled as JSON, optionally with indentation and color.
Use EvaluateStream when r holds a stream of values that the expression should aggregate across (via jq's input/inputs).
func EvaluateStream ¶
EvaluateStream runs a jq expression against a stream of JSON values read from r (values may be whitespace- or newline-separated, as produced by a JSONL writer). Output formatting matches Evaluate.
The expression is evaluated with jq's standard multi-input semantics: it runs once per input value (so a simple filter like `.name` prints one result per record), and the input/inputs builtins pull the remaining values from the same stream. This lets expressions aggregate across records, e.g. `[.,inputs] | length` or `reduce inputs as $x (0; . + $x.run_time)`.
Types ¶
type Error ¶
type Error struct {
Expr string // the offending jq expression
Err error // the underlying parse/compile/eval error
}
Error wraps a failure that originates in the jq expression itself — a parse error, a compile error, or a runtime evaluation error (e.g. building an object with a non-string key). Callers use errors.As to distinguish a bad --jq expression from input/data errors (a malformed value in the stream) so they can report it as an invalid argument rather than an API or I/O failure.