Documentation
¶
Overview ¶
Package jsonstrict holds the strict-JSON checks encoding/json does not make: the one place a repeated object key is refused rather than read last-wins, shared by every reader whose input is a trust boundary (the rules overlay, the release-gate receipts, the layered configuration files, the reading presets).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTrailing = errors.New("content after the one JSON document")
ErrTrailing is Decode's answer for data that carries anything after its one JSON document: a second document, or bytes that are not JSON at all.
Functions ¶
func Decode ¶
Decode is the strict decode a trust-boundary reader makes: data is exactly one JSON document, no object in it repeats a key (a *DuplicateKeyError, judged as NoDuplicateKeys judges it), no field is one v's type does not name (encoding/json's unknown-field error), and nothing follows the document (ErrTrailing). Whitespace after the document is not content.
func NoDuplicateKeys ¶
NoDuplicateKeys walks the JSON token stream and refuses any object that carries a repeated key at any nesting level, answering a *DuplicateKeyError. It runs before the unmarshal precisely because encoding/json would otherwise collapse the duplicate silently.
"Repeated" is judged the way encoding/json matches a key to a struct field: after unescaping, and case-insensitively under Unicode simple folding (its foldName, which agrees with strings.EqualFold), so "VerificationResult", "VERIFICATIONRESULT" and "\u0056erificationResult" all repeat "verificationResult". The checker does not know the target type, so it folds in every object, map-shaped ones included: a map encoding/json would keep two entries in ("PII" and "pii") is refused too, because one name in two spellings is illegible to the reader the refusal protects.
A malformed document answers nil and is left for the unmarshal to report with its position. The stdlib decoder enforces a max nesting depth, so no separate depth guard is needed.
Types ¶
type DuplicateKeyError ¶
DuplicateKeyError names one object key a document repeats. Key is the later spelling and First the earlier one it collides with: equal for an exact repeat, different for a case twin encoding/json binds to the same field. Path is the chain of enclosing object keys from the root, "[]" standing for an array element. Callers that phrase their own refusal read the fields; Error is the general form.
func (*DuplicateKeyError) Error ¶
func (e *DuplicateKeyError) Error() string