jsoniter

package
v0.0.0-...-179d86b Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jsoniter provides iterators over streamed JSON.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDecodingValue = errors.New("decoding value at position")
	ErrNoArrayBegin  = errors.New("no array begin token")
	ErrNoArrayEnd    = errors.New("no array end token")
	ErrReadingToken  = errors.New("no token read")
)

Functions

func DecodeArray

func DecodeArray[T any](r io.Reader) iter.Seq2[T, error]

DecodeArray returns an iterator over a JSON array's decoded values.

When it finds the ']' (array end) token, it stops iterating. However when it encounters an error, it also stops and returns a zero value [T], along with the encountered decoding error. In that case, it is up to the caller to either discard or keep the previously decoded values.

An empty JSON will return no error and no values to iterate over. Same goes for an invalid (nil) io.Reader.

type Entry struct { /* ... */ }
resp, _ := http.Get("...")
for entry, err := range jsoniter.DecodeArray[Entry](resp.Body) {
	if err != nil {
		// Nothing else can be decoded, do something with the error.
		break
	}

	// Do something with the decoded entry.
	_ = entry
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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