Skip to content

Commit

Permalink
encoding/json: clarify omitempty option for {array,slice,map,string}
Browse files Browse the repository at this point in the history
This CL is inspired by:
#29310 (comment)

When I read omitempty option in encoding/xml package, I find it's
a bit different than encoding/json package.

I think it's more precise to say:
"any array, slice, map, or string of length zero."

Update #29310

Change-Id: Ia77167c3155411640224b349d4b34d0bb91ee11e
GitHub-Last-Rev: a4cf00d
GitHub-Pull-Request: #69984
Reviewed-on: https://go-review.googlesource.com/c/go/+/621835
Auto-Submit: Ian Lance Taylor <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Joseph Tsai <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
  • Loading branch information
callthingsoff authored and gopherbot committed Oct 23, 2024
1 parent 3cb0c03 commit 9f26d35
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/encoding/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ import (
//
// The "omitempty" option specifies that the field should be omitted
// from the encoding if the field has an empty value, defined as
// false, 0, a nil pointer, a nil interface value, and any empty array,
// slice, map, or string.
// false, 0, a nil pointer, a nil interface value, and any array,
// slice, map, or string of length zero.
//
// As a special case, if the field tag is "-", the field is always omitted.
// Note that a field with name "-" can still be generated using the tag "-,".
Expand Down

0 comments on commit 9f26d35

Please sign in to comment.