jsonwire

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package jsonwire provides bounded, strict JSON helpers for interoperability boundaries where encoding/json's low-level defaults need explicit policy.

Index

Constants

View Source
const DefaultMaxBytes int64 = 1 << 20

DefaultMaxBytes is the default maximum payload size accepted by decoders.

Variables

View Source
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

type DecodeOptions struct {
	MaxBytes               int64
	DisallowUnknownFields  bool
	DisallowDuplicateNames bool
}

DecodeOptions controls JSON decoding behavior.

type EncodeOptions

type EncodeOptions struct {
	MaxBytes            int64
	Indent              string
	DisableHTMLEscaping bool
}

EncodeOptions controls JSON encoding behavior.

type NormalizeOptions

type NormalizeOptions struct {
	MaxBytes int64
}

NormalizeOptions controls JSON normalization behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL