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 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
All marshaling and unmarshaling semantics remain those of the standard library's encoding/json package.
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.
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.
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 default 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)`, 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.