Documentation
¶
Overview ¶
Package jsonbind provides generated, reflection-free JSON document codecs.
Index ¶
- Constants
- Variables
- func BytesJSONMap(data []byte) (map[string]json.RawMessage, error)
- func DecodeJSON[T any](r io.Reader) (T, error)
- func DecodeJSONBool(raw json.RawMessage) (bool, error)
- func DecodeJSONBoolSlice(raw json.RawMessage) ([]bool, error)
- func DecodeJSONFloat64(raw json.RawMessage) (float64, error)
- func DecodeJSONFloat64Slice(raw json.RawMessage) ([]float64, error)
- func DecodeJSONInt(raw json.RawMessage) (int, error)
- func DecodeJSONInt64(raw json.RawMessage) (int64, error)
- func DecodeJSONInt64Slice(raw json.RawMessage) ([]int64, error)
- func DecodeJSONIntSlice(raw json.RawMessage) ([]int, error)
- func DecodeJSONLimit[T any](r io.Reader, limit int64) (T, error)
- func DecodeJSONMapStringString(raw json.RawMessage) (map[string]string, error)
- func DecodeJSONString(raw json.RawMessage) (string, error)
- func DecodeJSONStringSlice(raw json.RawMessage) ([]string, error)
- func EncodeJSON[T any](w io.Writer, v T) error
- func FieldError(field, message string, cause error) error
- func MaxJSONBodyBytes() int64
- func RawJSONArray(raw json.RawMessage) ([]json.RawMessage, error)
- func RawJSONMap(raw json.RawMessage) (map[string]json.RawMessage, error)
- func ReadLimit(r io.Reader, limit int64) ([]byte, error)
- func RegisterDecode[T any](fn func([]byte) (T, error))
- func RegisterEncode[T any](fn func(io.Writer, T) error)
- func RestJSONAny(body map[string]json.RawMessage, exclude []string) (map[string]any, error)
- func RestJSONRaw(body map[string]json.RawMessage, exclude []string) map[string]json.RawMessage
- func SetMaxJSONBodyBytes(n int64)
- type Error
Constants ¶
const DefaultMaxJSONBodyBytes int64 = 1 << 20
DefaultMaxJSONBodyBytes is the default JSON document limit (1 MiB).
Variables ¶
var ErrBodyTooLarge = errors.New("jsonbind: JSON body too large")
ErrBodyTooLarge reports that a JSON document exceeded its configured limit.
Functions ¶
func BytesJSONMap ¶
func BytesJSONMap(data []byte) (map[string]json.RawMessage, error)
BytesJSONMap decodes a complete JSON object document.
func DecodeJSON ¶
DecodeJSON decodes one JSON value from r into T using a generated codec. It does not inspect HTTP headers or use reflection on T's fields.
func DecodeJSONBool ¶
func DecodeJSONBool(raw json.RawMessage) (bool, error)
func DecodeJSONBoolSlice ¶
func DecodeJSONBoolSlice(raw json.RawMessage) ([]bool, error)
func DecodeJSONFloat64 ¶
func DecodeJSONFloat64(raw json.RawMessage) (float64, error)
func DecodeJSONFloat64Slice ¶
func DecodeJSONFloat64Slice(raw json.RawMessage) ([]float64, error)
func DecodeJSONInt ¶
func DecodeJSONInt(raw json.RawMessage) (int, error)
func DecodeJSONInt64 ¶
func DecodeJSONInt64(raw json.RawMessage) (int64, error)
func DecodeJSONInt64Slice ¶
func DecodeJSONInt64Slice(raw json.RawMessage) ([]int64, error)
func DecodeJSONIntSlice ¶
func DecodeJSONIntSlice(raw json.RawMessage) ([]int, error)
func DecodeJSONLimit ¶
DecodeJSONLimit is DecodeJSON with a per-call byte limit. A non-positive limit uses MaxJSONBodyBytes.
func DecodeJSONMapStringString ¶
func DecodeJSONMapStringString(raw json.RawMessage) (map[string]string, error)
func DecodeJSONString ¶
func DecodeJSONString(raw json.RawMessage) (string, error)
func DecodeJSONStringSlice ¶
func DecodeJSONStringSlice(raw json.RawMessage) ([]string, error)
func EncodeJSON ¶
EncodeJSON encodes v as compact JSON to w using a generated codec. It does not set HTTP headers or status.
func FieldError ¶
FieldError annotates a JSON decoding error with its document field.
func MaxJSONBodyBytes ¶
func MaxJSONBodyBytes() int64
MaxJSONBodyBytes returns the effective JSON document limit.
func RawJSONArray ¶
func RawJSONArray(raw json.RawMessage) ([]json.RawMessage, error)
RawJSONArray decodes a JSON array into raw elements.
func RawJSONMap ¶
func RawJSONMap(raw json.RawMessage) (map[string]json.RawMessage, error)
RawJSONMap decodes a JSON object into raw fields.
func RegisterDecode ¶
RegisterDecode registers a generated JSON document decoder for T.
func RegisterEncode ¶
RegisterEncode registers a generated compact JSON encoder for T.
func RestJSONAny ¶
RestJSONAny returns JSON fields not named in exclude.
func RestJSONRaw ¶
func RestJSONRaw(body map[string]json.RawMessage, exclude []string) map[string]json.RawMessage
RestJSONRaw copies JSON fields not named in exclude.
func SetMaxJSONBodyBytes ¶
func SetMaxJSONBodyBytes(n int64)
SetMaxJSONBodyBytes changes the process-wide JSON document limit.