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 rejects unknown fields by default and accepts github.com/alexfalkowski/go-service/v2/encoding/codec.WithDiscardUnknown for forward-compatible API streams. It drops the sibling 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 ¶
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 ¶
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 are rejected unless codec.WithDiscardUnknown is supplied.
type 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 ¶
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.