Documentation
¶
Index ¶
- Variables
- func FuzzyAny(dec *jsontext.Decoder, t any) error
- func FuzzyBool(dec *jsontext.Decoder, t *bool) error
- func FuzzyFloat32(dec *jsontext.Decoder, t *float32) error
- func FuzzyFloat64(dec *jsontext.Decoder, t *float64) error
- func FuzzyInt(dec *jsontext.Decoder, t *int) error
- func FuzzyInt8(dec *jsontext.Decoder, t *int8) error
- func FuzzyInt16(dec *jsontext.Decoder, t *int16) error
- func FuzzyInt32(dec *jsontext.Decoder, t *int32) error
- func FuzzyInt64(dec *jsontext.Decoder, t *int64) error
- func FuzzyOriginUnmarshalers() []*json.Unmarshalers
- func FuzzyString(dec *jsontext.Decoder, t *string) error
- func FuzzyUint(dec *jsontext.Decoder, t *uint) error
- func FuzzyUint8(dec *jsontext.Decoder, t *uint8) error
- func FuzzyUint16(dec *jsontext.Decoder, t *uint16) error
- func FuzzyUint32(dec *jsontext.Decoder, t *uint32) error
- func FuzzyUint64(dec *jsontext.Decoder, t *uint64) error
Constants ¶
This section is empty.
Variables ¶
var FuzzyUnmarshaler = FuzzyUnmarshalerFull
var FuzzyUnmarshalerFull = sync.OnceValue(func() json.Options { unmarshalers := FuzzyOriginUnmarshalers() unmarshalers = append(unmarshalers, json.UnmarshalFromFunc(FuzzyAny)) return json.WithUnmarshalers( json.JoinUnmarshalers(unmarshalers...), ) })
var FuzzyUnmarshalerOrigin = sync.OnceValue(func() json.Options { return json.WithUnmarshalers( json.JoinUnmarshalers(FuzzyOriginUnmarshalers()...), ) })
Functions ¶
func FuzzyBool ¶
FuzzyBool is a custom JSON unmarshaler for the bool type that provides fuzzy decoding. It can decode a bool from JSON booleans, strings, numbers, and null.
func FuzzyFloat32 ¶
FuzzyFloat32 is a custom JSON unmarshaler for the float32 type that provides fuzzy decoding. See fuzzyFloat for more details on the decoding behavior.
func FuzzyFloat64 ¶
FuzzyFloat64 is a custom JSON unmarshaler for the float64 type that provides fuzzy decoding. See fuzzyFloat for more details on the decoding behavior.
func FuzzyInt ¶
FuzzyInt is a custom JSON unmarshaler for the int type that provides fuzzy decoding. It can decode an int from JSON numbers, strings, booleans, and null.
Behavior:
- JSON numbers (e.g., 123, 45.67) are decoded as integers (floats are truncated).
- JSON strings (e.g., "123", " 45.67 ") are parsed as integers after trimming whitespace (floats are truncated).
- JSON booleans are decoded as 1 for true and 0 for false.
- JSON null is decoded as 0.
- Empty strings or strings with only whitespace are decoded as 0.
func FuzzyInt8 ¶
FuzzyInt8 is a custom JSON unmarshaler for the int8 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
func FuzzyInt16 ¶
FuzzyInt16 is a custom JSON unmarshaler for the int16 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
func FuzzyInt32 ¶
FuzzyInt32 is a custom JSON unmarshaler for the int32 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
func FuzzyInt64 ¶
FuzzyInt64 is a custom JSON unmarshaler for the int64 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
func FuzzyOriginUnmarshalers ¶
func FuzzyOriginUnmarshalers() []*json.Unmarshalers
func FuzzyString ¶
FuzzyString is a custom JSON unmarshaler for the string type that provides fuzzy decoding. It can decode a string from JSON numbers, booleans, null, and strings.
Behavior:
- JSON strings (e.g., "hello") are decoded as is.
- JSON numbers (e.g., 123, 45.67) are converted to their string representation.
- JSON booleans are decoded as "true" or "false".
- JSON null is decoded as an empty string "".
func FuzzyUint ¶
FuzzyUint is a custom JSON unmarshaler for the uint type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
func FuzzyUint8 ¶
FuzzyUint8 is a custom JSON unmarshaler for the uint8 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
func FuzzyUint16 ¶
FuzzyUint16 is a custom JSON unmarshaler for the uint16 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
func FuzzyUint32 ¶
FuzzyUint32 is a custom JSON unmarshaler for the uint32 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.
Types ¶
This section is empty.