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 ¶
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