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 preserving the default behavior of the standard library encoder and decoder
- 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 JSON using the standard library implementation.
It exists so repository packages can use a single go-service JSON import path without changing standard library marshaling behavior.
func MarshalIndent ¶ added in v2.336.0
MarshalIndent encodes v as indented JSON using the standard library implementation.
It behaves exactly like `encoding/json.MarshalIndent`.
Types ¶
type Encoder ¶
type Encoder struct{}
Encoder implements JSON encoding and decoding.
It preserves the default behavior of the standard library `encoding/json` encoder and decoder and does not add repository-specific options.
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 its default settings.
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.