From a4cf00dcc75067bd259bc600f288c9de4b5393cf Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Tue, 22 Oct 2024 22:31:55 +0800 Subject: [PATCH] encoding/json: clarify omitempty option for {array,slice,map,string} This CL is inspired by: https://github.com/golang/go/issues/29310#issuecomment-758768325 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: I64aefea34327c503a9ab33fceca3e02a62cb673a --- src/encoding/json/encode.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 02522f088a070c..d53e862d73bce9 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -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 "-,".