0
1
mirror of https://github.com/golang/go synced 2024-11-24 14:36:17 +00:00
go/doc/next/6-stdlib/99-minor/encoding/json/45669.md
Jes Cok e86982c515 encoding/json: add omitzero option
Fixes #45669

Change-Id: Ic13523c0b3acdfc5b3e29a717bc62fde302ed8fd
GitHub-Last-Rev: 57030f26b0062fa8eda21b3a73b7665deab88c76
GitHub-Pull-Request: golang/go#69622
Reviewed-on: https://go-review.googlesource.com/c/go/+/615676
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-10-02 14:22:27 +00:00

452 B

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.

If both omitempty and omitzero are specified, the field will be omitted if the value is either empty or zero (or both).