jq

package module
v0.0.0-...-f9de311 Latest Latest
Warning

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

Go to latest
Published: May 31, 2017 License: GPL-2.0 Imports: 6 Imported by: 0

README

jq-go

A Go language binding for the JQ JSON filter library

Documentation

Overview

This package wraps https://github.com/stedolan/jq as a virtual machine. This provides Go programmers with a way to filter JSON data using JQ.

Building this package requires a very current build of JQ; earlier releases do not provide JQ as a separate library component. For a more stable and portable implementation, see https://github.com/threatgrid/jqpipe-go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(proc string, input ...interface{}) ([][]byte, error)

Apply compiles a JQ filter, and applies it to one or more inputs.

func Dump

func Dump(w io.Writer, proc string, input ...interface{}) error

Dump dumps the results of Apply to a writer, following each result with a newline.

Types

type Vm

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

A Vm encloses the internal state of a compiled JQ filter machine. Vm's can be reused, but cannot be used concurrently.

func Compile

func Compile(proc string) (*Vm, error)

Compile compiles a JQ filter into a new JQ virtual machine.

func MustCompile

func MustCompile(proc string) *Vm

MustCompile uses Compile to compile a JQ filter, and panics if it fails. This simplifies wrapping a known good filter into global variable.

func (*Vm) Apply

func (s *Vm) Apply(input ...interface{}) ([][]byte, error)

Apply runs the JQ filter on each input after using encoding/json to convert to JSON. The results of each run are combined into an array of JSON raw messages. Apply stops on the first error, which could be during Compile or a Run.

func (*Vm) Close

func (s *Vm) Close() error

Close closes a JQ state, releasing resources.

func (*Vm) Dump

func (vm *Vm) Dump(w io.Writer, input ...interface{}) error

Dump applies a filter to zero or more inputs, and writes the JSON results to an io.Writer.

func (*Vm) Run

func (s *Vm) Run(input []byte, e *error) chan []byte

Run starts the filter with the supplied input, and uses a channel to gather results. When the channel is closed, e will contain the final error, if any. Run may be used consecutively for additional inputs, but not in parallel.

Jump to

Keyboard shortcuts

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