jsonlimit

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Overview

Package jsonlimit validates untrusted JSON structure before application decoders allocate recursive values. Byte limits alone do not prevent deeply nested or highly fragmented documents from consuming disproportionate CPU and stack space.

Index

Constants

View Source
const (
	// DefaultMaxDepth leaves room for Ridu's bounded rich-text documents and
	// their request envelope while rejecting pathological JSON nesting.
	DefaultMaxDepth = 128
	// DefaultMaxTokens is deliberately well above an ordinary one-megabyte
	// document, but provides a stable ceiling when callers raise byte limits.
	DefaultMaxTokens = 100_000
)

Variables

View Source
var (
	ErrTooDeep       = errors.New("JSON nesting exceeds the configured limit")
	ErrTooManyTokens = errors.New("JSON token count exceeds the configured limit")
	ErrDuplicateKey  = errors.New("JSON object contains a duplicate key")
)

Functions

func Validate

func Validate(encoded []byte, maxDepth, maxTokens int) error

Validate rejects malformed JSON, excessive depth/token counts, and duplicate object keys. The caller still decodes the value into its concrete contract afterwards; this pass exists to bound and disambiguate that work.

Types

This section is empty.

Jump to

Keyboard shortcuts

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