json

package
v2.752.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package json provides a streaming JSON github.com/alexfalkowski/go-service/v2/encoding/stream.Encoder/ github.com/alexfalkowski/go-service/v2/encoding/stream.Decoder pair used by go-service.

It wraps the standard library encoding/json package's own NewEncoder/NewDecoder types, which are each bound to one writer/reader for many Encode/Decode calls. It carries over the strict decoding policy of github.com/alexfalkowski/go-service/v2/encoding/json (unknown fields rejected), but drops that package's indentation (which would break newline-delimited framing) and trailing-data rejection (a stream is expected to contain many values).

Start with the package-level constructors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	*json.Decoder
}

Decoder streams JSON values from a reader bound at construction.

Decoder embeds the standard library's encoding/json.Decoder, so [Decoder.Decode] is the embedded decoder's own method. Decoder satisfies github.com/alexfalkowski/go-service/v2/encoding/stream.Decoder structurally, without this package importing that package.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder constructs a streaming JSON Decoder bound to r.

Unlike github.com/alexfalkowski/go-service/v2/encoding/json.Encoder's Decode, the returned decoder allows additional JSON values after the first: it does not enforce single-value trailing-data rejection, since a stream is expected to carry many values. Unknown fields remain rejected.

func (*Decoder) Close

func (d *Decoder) Close() error

Close is a no-op: the standard library JSON decoder has no finalization state to flush.

type Encoder

type Encoder struct {
	*json.Encoder
}

Encoder streams JSON values to a writer bound at construction.

Encoder embeds the standard library's encoding/json.Encoder, so [Encoder.Encode] is the embedded encoder's own method. Encoder satisfies github.com/alexfalkowski/go-service/v2/encoding/stream.Encoder structurally, without this package importing that package: github.com/alexfalkowski/go-service/v2/encoding/stream.NewMap imports this package to pre-register the default "json" kind, and this package importing that one back would be a compile-time import cycle.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder constructs a streaming JSON Encoder bound to w.

Unlike github.com/alexfalkowski/go-service/v2/encoding/json.Encoder, the returned encoder writes no indentation, so consecutive values stay newline-delimited (NDJSON) instead of each spanning multiple lines.

func (*Encoder) Close

func (e *Encoder) Close() error

Close is a no-op: the standard library JSON encoder has no finalization state to flush.

Jump to

Keyboard shortcuts

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