// - bool, for JSON booleans
// - float64, for JSON numbers
// - string, for JSON strings
-// - []interface{}, for JSON arrays
-// - map[string]interface{}, for JSON objects
+// - []any, for JSON arrays
+// - map[string]any, for JSON objects
// - nil for JSON null
//
// To unmarshal a JSON array into a slice, Unmarshal resets the slice length
}
// Prevent infinite loop if v is an interface pointing to its own address:
- // var v interface{}
+ // var v any
// v = &v
if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
v = v.Elem()
// in an empty interface. They are not strictly necessary,
// but they avoid the weight of reflection in this common case.
-// valueInterface is like value but returns interface{}
+// valueInterface is like value but returns any.
func (d *decodeState) valueInterface() (val any) {
switch d.opcode {
default:
return
}
-// arrayInterface is like array but returns []interface{}.
+// arrayInterface is like array but returns []any.
func (d *decodeState) arrayInterface() []any {
var v = make([]any, 0)
for {
return v
}
-// objectInterface is like object but returns map[string]interface{}.
+// objectInterface is like object but returns map[string]any.
func (d *decodeState) objectInterface() map[string]any {
m := make(map[string]any)
for {
// Here we use a struct to memorize the pointer to the first element of the slice
// and its length.
ptr := struct {
- ptr interface{} // always an unsafe.Pointer, but avoids a dependency on package unsafe
+ ptr any // always an unsafe.Pointer, but avoids a dependency on package unsafe
len int
}{v.UnsafePointer(), v.Len()}
if _, ok := e.ptrSeen[ptr]; ok {
}`))
f.Fuzz(func(t *testing.T, b []byte) {
- for _, typ := range []func() interface{}{
- func() interface{} { return new(interface{}) },
- func() interface{} { return new(map[string]interface{}) },
- func() interface{} { return new([]interface{}) },
+ for _, typ := range []func() any{
+ func() any { return new(any) },
+ func() any { return new(map[string]any) },
+ func() any { return new([]any) },
} {
i := typ()
if err := Unmarshal(b, i); err != nil {
return &Decoder{r: r}
}
-// UseNumber causes the Decoder to unmarshal a number into an interface{} as a
-// [Number] instead of as a float64.
+// UseNumber causes the Decoder to unmarshal a number into an
+// interface value as a [Number] instead of as a float64.
func (dec *Decoder) UseNumber() { dec.d.useNumber = true }
// DisallowUnknownFields causes the Decoder to return an error when the destination