jq

package
v1.0.47653 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 11 Imported by: 0

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

func Evaluate(r io.Reader, w io.Writer, opts Options) error

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

func EvaluateStream(r io.Reader, w io.Writer, opts Options) error

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.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Options

type Options struct {
	Expr     string
	Indent   string
	Colorize bool
}

Options controls how Evaluate formats its output.

Jump to

Keyboard shortcuts

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