You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using json v2, we need to set OmitZeroStructFields to true during unmarshal.
Another option is to replace omitempty by omitzero in the struct tag. Note that the behavior does not change for strings, slices or maps.
GOEXPERIMENT=jsonv2 go run jsontest.go
{"name":"test struct"}
{"name":"test struct","valueInt":0,"valueStruct":{"AnotherValue":""}}
{"name":"test struct"}
Activity
lpic10 commentedon Sep 2, 2025
Updated, we need to set
OmitEmptyWithLegacySemantics, as theOmitZeroStructFieldswill have unintended effects, see below