jpv

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

Decoder reads input in JPV format and streams it into a JSON stream.

JPV is a format that can represent values where each line specifies a leaf value and its path. A Lines are separated by '\n' and are of the form

<path> = <value>

where <path> is a JSONPath and <value> is a JSON value. E.g.

{"name": "Dan", "parent_ids": [132, 7650]}

is represented as

$.["name"] = "Dan"
$.["parent_ids"][0] = 132
$.["parent_ids"][1] = 7650

The potential value in this format is that it can be piped through grep and other unix utilites to be filtered / transformed, then turned back into JSON.

func NewDecoder

func NewDecoder(in io.Reader) *Decoder

NewDecoder sets up a new Decoder instance to read from the given input.

func (*Decoder) Produce

func (d *Decoder) Produce(out chan<- token.Token) error

Produce reads a stream of JPV values and streams them, until it runs out of input or encounters invalid JPV, in which case it will return an error.

type Encoder

type Encoder struct {
	format.Printer
	*format.Colorizer

	AlwaysQuoteKeys bool
	// contains filtered or unexported fields
}

A Encoder can output a stream encoding a JSON value using the given Printer instance for formatting. It prints the JSON value in the JPV format (see Decoder for details of the format).

func (*Encoder) Consume

func (e *Encoder) Consume(stream <-chan token.Token) (err error)

Consume formats the JSON stream encoded in the given channel using the instance's Printer. It assumes that the stream is well-formed, i.e. is a valid encoding for a stream of JSON values and may panic if that is not the case.

And error can be returned if the Printer could not perform some writing operation. A typical example is if it attempt to write to a closed pipe.

Jump to

Keyboard shortcuts

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