Documentation
¶
Overview ¶
Package json provides the go-service JSON import path.
The package serves two related purposes:
- it exposes Encoder, a thin adapter that satisfies the repository's generic encoding abstraction while using readable indented encoding and strict standard library decoding
- it re-exports common JSON helpers and types from the standard library so packages in this repository can depend on a single go-service JSON import path instead of importing encoding/json directly
Marshal and Valid preserve the standard library's encoding/json semantics. Encoder and Unmarshal use the standard decoder with unknown fields and trailing values rejected. Duplicate object keys keep the standard library's last-wins behavior.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶ added in v2.336.0
Marshal encodes v as readable indented JSON.
It exists so repository packages can use a single go-service JSON import path.
func Unmarshal ¶ added in v2.336.0
Unmarshal decodes one JSON value from data into v.
It uses Decode, so it rejects additional JSON values after the first payload.
func Valid ¶ added in v2.336.0
Valid reports whether data is syntactically valid JSON.
It behaves exactly like encoding/json.Valid.
Types ¶
type Encoder ¶
type Encoder struct{}
Encoder implements JSON encoding and decoding.
It writes readable indented JSON and uses the standard library encoding/json decoder with unknown fields and trailing values rejected.
func NewEncoder ¶
func NewEncoder() *Encoder
NewEncoder constructs a JSON encoder.
NewEncoder returns an Encoder that satisfies github.com/alexfalkowski/go-service/v2/encoding.Encoder while delegating to the standard library's encoding/json implementation with readable indented encoding and strict decoding.
func (*Encoder) Decode ¶
Decode reads JSON from r and decodes it into v.
In most cases v should be a pointer to the destination value, such as `*MyStruct` or `*map[string]any`. Decode is equivalent to calling `json.NewDecoder(r).Decode(v)` with unknown fields rejected, then requiring the stream to contain no additional JSON values.
Duplicate JSON object keys keep the standard library's last-wins behavior.
type Marshaler ¶ added in v2.336.0
Marshaler aliases the standard library JSON marshaler interface.
Use this alias when a package wants to refer to the marshaling contract while keeping imports within the go-service JSON package.
type Number ¶ added in v2.336.0
Number aliases the standard library JSON number type.
It is primarily useful with decoders configured to preserve numeric values as strings until the caller decides how to interpret them.
type RawMessage ¶ added in v2.336.0
type RawMessage = json.RawMessage
RawMessage aliases the standard library raw JSON message type.
It is useful when callers need to defer decoding or preserve the original encoded JSON payload.
type Unmarshaler ¶ added in v2.336.0
type Unmarshaler = json.Unmarshaler
Unmarshaler aliases the standard library JSON unmarshaler interface.
Use this alias when a package wants to refer to the unmarshaling contract while keeping imports within the go-service JSON package.