Documentation
¶
Overview ¶
Package strictjson reads native Ceph JSON without the silent choices of encoding/json. A document is exactly one JSON value: no object repeats a key at any depth, nesting stays within MaxDepth and nothing follows the value. When the document is decoded into a typed value, a key that differs from a known field's name only by case is refused instead of adopted by the decoder's case-insensitive matching, and unrelated unknown keys are allowed.
Errors are the sentinels below and never copy native data, which can carry credentials, into their text.
Index ¶
Constants ¶
const MaxDepth = 64
MaxDepth bounds the nesting of objects and arrays. Native Ceph output nests far less deeply; the bound keeps a hostile document from growing the stack.
Variables ¶
var ( // ErrSize reports an empty document or one larger than Options.MaxBytes. ErrSize = errors.New("JSON document is empty or too large") // ErrMalformed reports invalid JSON, or a value of the wrong type for the // field it is decoded into. ErrMalformed = errors.New("malformed JSON document") // ErrDuplicateKey reports an object that repeats a key. ErrDuplicateKey = errors.New("duplicate JSON object key") // ErrNoncanonicalKey reports a key that matches a known field only when // case is ignored. ErrNoncanonicalKey = errors.New("noncanonical JSON object key") // ErrNull reports null for a known field when Options.RejectNull is set. ErrNull = errors.New("null JSON value for a known field") // ErrDepth reports nesting beyond MaxDepth. ErrDepth = errors.New("JSON nesting exceeds limit") // ErrTrailing reports data after the first JSON value. ErrTrailing = errors.New("trailing data after the JSON value") )
Functions ¶
Types ¶
type Options ¶
type Options struct {
// MaxBytes refuses a larger document. Zero sets no size limit; an empty
// document is refused either way.
MaxBytes int
// RejectNull refuses null for any field whose type is known from the
// decoded value, so a present but null field cannot pass as absent.
RejectNull bool
// UseNumber decodes numbers in interface values as json.Number.
UseNumber bool
}
Options holds the rules that legitimately differ between callers.