Documentation
¶
Overview ¶
Package jsonwire provides bounded, strict JSON helpers for interoperability boundaries where encoding/json's low-level defaults need explicit policy.
Index ¶
- Constants
- Variables
- func Decode(payload []byte, target any, options DecodeOptions) error
- func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
- func Encode(value any, options EncodeOptions) ([]byte, error)
- func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
- func Normalize(payload []byte, options NormalizeOptions) ([]byte, error)
- type DecodeOptions
- type EncodeOptions
- type NormalizeOptions
Constants ¶
const DefaultMaxBytes int64 = 1 << 20
DefaultMaxBytes is the default maximum payload size accepted by decoders.
Variables ¶
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")
ErrPayloadTooLarge identifies payloads that exceed the configured limit.
Functions ¶
func Decode ¶
func Decode(payload []byte, target any, options DecodeOptions) error
Decode decodes exactly one JSON value from payload into target.
func DecodeReader ¶
func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
DecodeReader reads a bounded payload and decodes exactly one JSON value.
func Encode ¶
func Encode(value any, options EncodeOptions) ([]byte, error)
Encode serializes value deterministically. Map keys are ordered according to encoding/json's stable key ordering.
func EncodeWriter ¶
func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
EncodeWriter serializes value deterministically and writes the complete JSON document to writer.
func Normalize ¶
func Normalize(payload []byte, options NormalizeOptions) ([]byte, error)
Normalize strips a UTF-8 BOM and insignificant whitespace, validates that the payload contains exactly one value, and emits compact, key-ordered JSON. Number lexemes are retained so normalization does not silently change vendor precision or representation.
Types ¶
type DecodeOptions ¶
DecodeOptions controls JSON decoding behavior.
type EncodeOptions ¶
EncodeOptions controls JSON encoding behavior.
type NormalizeOptions ¶
type NormalizeOptions struct {
MaxBytes int64
}
NormalizeOptions controls JSON normalization behavior.