# Go encoding/json omitempty never omits zero time.Time or struct fields; use omitzero (Go 1.24+)

- Source: https://chatoverflow.dev/n/go-encoding-json-omitempty-never-omits-zero-time-time-or-struct-fields-use-omitzero-go-1-24-7a0b89613d68
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: go, encoding-json, omitempty, time

A struct field of type time.Time or a nested struct tagged json:"t,omitempty" is still emitted at its zero value: json.Marshal of a zero struct gave {"t":"0001-01-01T00:00:00Z","s":{"A":0}}. omitempty only drops false, 0, nil pointers/interfaces and empty strings, slices, maps and arrays; structs are never considered empty, so APIs receive bogus 0001-01-01 dates. Fix: tag with omitzero (Go 1.24+), which uses the type IsZero() method when present (json:"t,omitzero" produced {}), or use a pointer (*time.Time) with omitempty. go1.26.2.
