fuzzy

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuzzyUnmarshaler = FuzzyUnmarshalerFull
View Source
var FuzzyUnmarshalerFull = sync.OnceValue(func() json.Options {
	unmarshalers := FuzzyOriginUnmarshalers()
	unmarshalers = append(unmarshalers, json.UnmarshalFromFunc(FuzzyAny))

	return json.WithUnmarshalers(
		json.JoinUnmarshalers(unmarshalers...),
	)
})
View Source
var FuzzyUnmarshalerOrigin = sync.OnceValue(func() json.Options {
	return json.WithUnmarshalers(
		json.JoinUnmarshalers(FuzzyOriginUnmarshalers()...),
	)
})

Functions

func FuzzyAny

func FuzzyAny(dec *jsontext.Decoder, t any) error

func FuzzyBool

func FuzzyBool(dec *jsontext.Decoder, t *bool) error

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

func FuzzyFloat32(dec *jsontext.Decoder, t *float32) error

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

func FuzzyFloat64(dec *jsontext.Decoder, t *float64) error

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

func FuzzyInt(dec *jsontext.Decoder, t *int) error

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

func FuzzyInt8(dec *jsontext.Decoder, t *int8) error

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

func FuzzyInt16(dec *jsontext.Decoder, t *int16) error

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

func FuzzyInt32(dec *jsontext.Decoder, t *int32) error

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

func FuzzyInt64(dec *jsontext.Decoder, t *int64) error

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

func FuzzyString(dec *jsontext.Decoder, t *string) error

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

func FuzzyUint(dec *jsontext.Decoder, t *uint) error

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

func FuzzyUint8(dec *jsontext.Decoder, t *uint8) error

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

func FuzzyUint16(dec *jsontext.Decoder, t *uint16) error

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

func FuzzyUint32(dec *jsontext.Decoder, t *uint32) error

FuzzyUint32 is a custom JSON unmarshaler for the uint32 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.

func FuzzyUint64

func FuzzyUint64(dec *jsontext.Decoder, t *uint64) error

FuzzyUint64 is a custom JSON unmarshaler for the uint64 type that provides fuzzy decoding. See FuzzyInt for more details on the decoding behavior.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL