Skip to content

Add support for omitzero struct field option #147

Description

@ClifHouck

Go 1.24's json/encoding has added support for a new struct field option: omitzero.

From Go 1.24's release notes:

When marshaling, a struct field with the new omitzero option in the struct field tag will be omitted if its value is zero. If the field type has an IsZero() bool method, that will be used to determine whether the value is zero. Otherwise, the value is zero if it is the zero value for its type. The omitzero field tag is clearer and less error-prone than omitempty when the intent is to omit zero values. In particular, unlike omitempty, omitzero omits zero-valued time.Time values, which is a common source of friction.

This is a really nice addition, especially for JSON PATCH requests.

Could json-to-go support this alongside the omitempty option?

BTW your tool has been really useful to me. Thanks for putting out there!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions