Help us shape the future of Go! Take the 2026 Go Developer Survey

jsonwire

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package jsonwire owns bounded, lossless JSON parsing for typed values and transport.

Index

Constants

View Source
const (
	MaxBytes = 1 << 20
	MaxDepth = 64
	MaxNodes = 10000
)

Variables

This section is empty.

Functions

func Canonical

func Canonical(data []byte, limits Limits) ([]byte, error)

Canonical preserves transport strings (including escaped NUL), sorts object names, normalizes exact decimal numbers and retains array order. It shares the same parser and budgets as Decode and storage Parse.

func Decode

func Decode(data []byte, limits Limits) (any, error)

Decode reads a transport document without storage-specific normalization. Numbers retain their exact input lexeme as json.Number. Escaped NUL is valid JSON and remains intact; codecs and application validation can reject it. Callers bound the body before supplying its bytes. No canonical copy is made.

func Measure

func Measure(data []byte, limits Limits) error

Measure bounds a document already produced by a validating encoder, such as encoding/json/v2 with duplicate names and invalid UTF-8 rejected. It rechecks bytes, UTF-8 and escapes, then counts depth and nodes exactly as Decode does, in one allocation-free pass without building a tree. It does not re-validate general JSON syntax; use Decode for untrusted input.

func Parse

func Parse(data []byte) (string, any, error)

Parse rejects duplicate object keys, lossy Unicode and PostgreSQL text NUL. Numbers retain exact canonical decimal text, never an intermediate float.

Types

type Limits

type Limits struct {
	Bytes int
	Depth int
	Nodes int
}

Limits bounds one transport document. Bytes and Nodes must be positive. Depth is the maximum child depth, with the root at zero; it may be reduced below MaxDepth but cannot exceed that parser recursion bound. Object names consume one node each in addition to their values. There are no implicit transport defaults here: the calling boundary owns its configuration.

Jump to

Keyboard shortcuts

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