I have a struct which correctly marshals to and unmarshals from JSON with the following struct tag:
type nodeJSON struct {
// omitted...
Subtract *binaryJSON `json:"-,omitempty"`
// omitted...
}
However, since upgrading to staticcheck v0.7.0, I've been getting this false positive:
internal/json/json.go:112:33: should encoding/json ignore this field or name it "-"? Either use `json:"-"` to ignore the field or use `json:"'-',omitempty"` to specify "-" as the name (SA5008)
As near as I can tell, there's nothing wrong with the current construction. The suggested fix is new syntax that is only available if using the encoding/json/v2 package, which I am not.
Particulars
staticcheck -version: staticcheck 2026.1 (v0.7.0)
staticcheck -debug.version:
staticcheck 2026.1 (v0.7.0)
Compiled with Go version: go1.25.6
Main module:
honnef.co/go/[email protected] (sum: h1:w6WUp1VbkqPEgLz4rkBzH/CSU6HkoqNLp6GstyTx3lU=)
Dependencies:
github.com/BurntSushi/[email protected] (sum: h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=)
golang.org/x/exp/[email protected] (sum: h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=)
golang.org/x/[email protected] (sum: h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=)
golang.org/x/[email protected] (sum: h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=)
golang.org/x/[email protected] (sum: h1:CHVDrNHx9ZoOrNN9kKWYIbT5Rj+WF2rlwPkhbQQ5V4U=)
I have a struct which correctly marshals to and unmarshals from JSON with the following struct tag:
However, since upgrading to
staticcheckv0.7.0, I've been getting this false positive:As near as I can tell, there's nothing wrong with the current construction. The suggested fix is new syntax that is only available if using the
encoding/json/v2package, which I am not.Particulars
staticcheck -version:staticcheck 2026.1 (v0.7.0)staticcheck -debug.version:go version:go version go1.25.6 darwin/arm64go env: ... please just let me know any relevant values I should post; I'm not going to post the full thingstaticcheck ./internal/json