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

jsonstrict

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package jsonstrict provides a small, dialect-agnostic JSON scan used by every codec/*api server-decode path to reject a request body that smuggles a duplicate object member name. encoding/json silently takes the last occurrence of a duplicate key; each dialect's DecodeRequest instead rejects the request outright so a client cannot smuggle a semantically different value past a naive review of the first occurrence.

This package was extracted after the identical scan had been independently copy-pasted into four sibling packages (anthropicapi, geminiapi, openairesponses, openaiapi) — a threshold each implementer was told, at the time, not to preemptively generalize away, since only a fourth copy proves the repetition durable enough to warrant a shared dependency. It is unexported from outside the module (see internal/usagenorm for the same convention) because the scan is an implementation detail of those four dialects' decoders, not a public contract of this module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RejectDuplicateKeys

func RejectDuplicateKeys(raw []byte) error

RejectDuplicateKeys reports the first duplicate object member name found anywhere in raw (at any nesting depth), as *DuplicateKeyError, or nil if raw has none. A JSON syntax error is reported as *MalformedError: this function's job is not to validate JSON, but it must never silently accept a body it cannot fully walk.

Types

type DuplicateKeyError

type DuplicateKeyError struct{ Key string }

DuplicateKeyError reports the first duplicate JSON object member name found.

func (*DuplicateKeyError) Error

func (e *DuplicateKeyError) Error() string

type MalformedError

type MalformedError struct{ Detail string }

MalformedError reports a JSON body that could not be fully walked (a syntax error or mismatched delimiter encountered while scanning).

func (*MalformedError) Error

func (e *MalformedError) Error() string

Jump to

Keyboard shortcuts

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