jsonwire

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 11 Imported by: 9 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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