With json v2, you can have this struct
type Foo struct {
// Known fields
A int `json:"a"`
B int `json:"b"`
// The type may be a jsontext.Value or map[string]T.
Unknown jsontext.Value `json:",unknown"`
}
Official documentation and example here: https://pkg.go.dev/github.com/go-json-experiment/json#example-package-UnknownMembers