On Thu, Sep 3, 2020 at 2:32 PM Alexander Mills
<
alexande...@gmail.com> wrote:
>
> I was under the impression it wouldn't omit the array if it had zero length, hence my question..
> i mean at some point we want an empty array in JSON, so I assume it's included by default
If you define boolField as a type, then you can have a custom
marshaler that checks array sizes, something like this:
func (b boolField) MarshalJSON() ([]byte,error) {
data:=map[string]interface{}{}
if len(b.Must)>0 {
data["must"]=b.Must
}
...
return json.Marshal(data)
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
golang-nuts...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/7df1c875-ed2e-46c4-a6f3-2064485de805n%40googlegroups.com.