Inspectopedia 2026.2 Help

'omitempty' tag on a struct field can be changed

Reports JSON struct tags that use ,omitempty on struct-typed fields.

For struct values, ,omitempty does not omit the field, because a struct value is never nil.

In Go 1.24 and later, ,omitzero omits the field when the struct value is the zero value.

Note: Replacing ,omitempty with ,omitzero is a behavior change. The field may be omitted in cases where it was previously always present.

Example:

type Event struct { CreatedAt time.Time `json:"created_at,omitempty"` Source Source `json:"source,omitempty"` }

To fix the code, do one of the following:

  • Use the Remove redundant omitempty tag quick-fix to keep the current JSON output.

  • Use the Replace omitempty with omitzero (behavior change) quick-fix to omit the field when the struct value is zero.

After the quick-fix that removes the tag:

type Event struct { CreatedAt time.Time `json:"created_at"` Source Source `json:"source"` }
type Event struct { CreatedAt time.Time `json:"created_at,omitzero"` Source Source `json:"source,omitzero"` }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

GoFixOmitZero
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Go | Go fix

Inspection ID: GoFixOmitZero

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection GoFixOmitZero

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

GoLand 2026.2, Qodana for Go 2026.2,

Last modified: 30 June 2026