jq

package
v0.0.0-...-7cd1858 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Query

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

Query contains the data and logic needed to evaluate a query. Instances are created using the Compile or Evaluate methods of the Tool type.

func (*Query) Evaluate

func (q *Query) Evaluate(input, output any, variables ...Variable) error

Evaluate evaluates the query with on the given input. The output should be a pointer to a variable where the result will be stored. Optional named variables can be passed.

type Tool

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

Tool knows how to run JQ queries. Don't create instances of this directly, use the NewTool function instead.

func (*Tool) Compile

func (t *Tool) Compile(source string, variables ...string) (result *Query, err error)

Compile compiles the given query and saves it in a cache, so that evaluating the same query with the same variables later will not require compile it again.

func (*Tool) Evaluate

func (t *Tool) Evaluate(source string, input, output any, variables ...Variable) error

Evaluate compiles the query and then evaluates it. The input can be any kind of object that can be serialized to JSON.

func (*Tool) EvaluateBytes

func (t *Tool) EvaluateBytes(source string, input []byte, output any, variables ...Variable) error

EvaluateBytes compiles the query and then evaluates it. The input should be an array of bytes containing a JSON document.

func (*Tool) EvaluateString

func (t *Tool) EvaluateString(source, input string, output any, variables ...Variable) error

EvaluateString compiles the query and then evaluates it. The input should be a string containing a JSON document.

type ToolBuilder

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

ToolBuilder contains the data needed to build a tool that knows how to run JQ queries. Don't create instances of this directly, use the NewTool function instead.

func NewTool

func NewTool() *ToolBuilder

NewTool creates a builder that can then be used to create a JQ tool.

func (*ToolBuilder) Build

func (b *ToolBuilder) Build() (result *Tool, err error)

Build uses the information stored in the builder to create a new JQ tool.

func (*ToolBuilder) SetCompilerOption

func (b *ToolBuilder) SetCompilerOption(value *gojq.CompilerOption) *ToolBuilder

SetCompilerOption sets the CompileOption to pass to gojq.Compile. This is optional.

func (*ToolBuilder) SetLogger

func (b *ToolBuilder) SetLogger(value *slog.Logger) *ToolBuilder

SetLogger sets the logger that the JQ tool will use to write the log. This is mandatory.

type Variable

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

func Any

func Any(name string, value any) Variable

func Int

func Int(name string, value int) Variable

func String

func String(name, value string) Variable

Jump to

Keyboard shortcuts

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