json

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: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectByte

func ExpectByte(scanr *scanner.Scanner, xb byte) error

func ParseNumber

func ParseNumber(scanr *scanner.Scanner) (*token.Scalar, error)

ParseNumber parses a JSON number from the scanner. Exported for use by other format decoders.

func ParseString

func ParseString(scanr *scanner.Scanner) (*token.Scalar, error)

func ReadDigits

func ReadDigits(scanr *scanner.Scanner) (byte, int, error)

func UnexpectedByte

func UnexpectedByte(scanr *scanner.Scanner, expected string, args ...interface{}) error

Types

type Decoder

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

A Decoder reads JSON input and streams it into a JSON stream.

func NewDecoder

func NewDecoder(in io.Reader) *Decoder

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

func NewDecoderFromScanner

func NewDecoderFromScanner(scanr *scanner.Scanner) *Decoder

NewDecoderFromScanner creates a decoder using an existing scanner. This is useful for format decoders that need to parse JSON values inline.

func (*Decoder) ParseValue

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

parseValue reads a single JSON value and streams it. It can return a non-nil error if the input is invalid JSON.

func (*Decoder) Produce

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

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

type Encoder

type Encoder struct {
	format.Printer
	*format.Colorizer
	CompactWidthLimit     int
	CompactObjectMaxItems int
}

An Encoder can output a stream encoding a (stream of) JSON values using the given Printer instance for formatting.

func (*Encoder) Consume

func (sw *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