Skip to content

SA5008: false positive on json:"-,omitempty" struct tag #1699

@patjakdev

Description

@patjakdev

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/tools@v0.7.0 (sum: h1:w6WUp1VbkqPEgLz4rkBzH/CSU6HkoqNLp6GstyTx3lU=)
Dependencies:
        github.com/BurntSushi/toml@v1.4.1-0.20240526193622-a339e1f7089c (sum: h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=)
        golang.org/x/exp/typeparams@v0.0.0-20231108232855-2478ac86f678 (sum: h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=)
        golang.org/x/mod@v0.31.0 (sum: h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=)
        golang.org/x/sync@v0.19.0 (sum: h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=)
        golang.org/x/tools@v0.40.1-0.20260108161641-ca281cf95054 (sum: h1:CHVDrNHx9ZoOrNN9kKWYIbT5Rj+WF2rlwPkhbQQ5V4U=)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions