jsonstream

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package jsonstream copies JSON objects from a reader to a writer one member at a time, so a document can be filtered without holding it in memory. Values that are kept are written with their original bytes.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotObject = errors.New("JSON value is not an object")

ErrNotObject is returned when a value expected to be an object is not.

Functions

func CopyObject

func CopyObject(dec *json.Decoder, w io.Writer, fn func(*Member) error) error

CopyObject copies the object read from dec to w, calling fn for each member. fn decides what is written by how it consumes the member's value; a member whose value fn leaves unconsumed is copied unchanged.

Types

type Member

type Member struct {
	Key string
	// contains filtered or unexported fields
}

Member is one member of an object being copied. Its value must be consumed exactly once, with Raw, Copy or Object.

func (*Member) Copy

func (m *Member) Copy() error

Copy writes the member with its value unchanged.

func (*Member) Object

func (m *Member) Object(fn func(*Member) error) error

Object writes the member and copies its value, which must be an object, calling fn for each of its members. A null value is written as null.

func (*Member) Raw

func (m *Member) Raw() (json.RawMessage, error)

Raw reads the member's value without writing it. Follow it with Write to keep the member.

func (*Member) Write

func (m *Member) Write(value []byte) error

Write writes the member with value as its raw JSON value.

Jump to

Keyboard shortcuts

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