Re: [go-nuts] Re: how to omit empty array

2020-09-03 Thread Nishanth Shanmugham
> I was under the impression it wouldn't omit the array if it had zero length, hence my question. Using omitempty omits the array/slice field in the encoding if it is zero length. Check out https://play.golang.org/p/B1LcICyEfeK. Related encoding/json pack

Re: [go-nuts] Re: how to omit empty array

2020-09-03 Thread burak serdar
On Thu, Sep 3, 2020 at 2:32 PM Alexander Mills 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

[go-nuts] Re: how to omit empty array

2020-09-03 Thread Alexander Mills
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 On Thursday, September 3, 2020 at 3:35:05 AM UTC-7 nishanth...@gmail.com wrote: > > how do I omit an array

[go-nuts] Re: how to omit empty array

2020-09-03 Thread Nishanth Shanmugham
> how do I omit an array on boolField if the array is empty? Do you mean how to omit an empty array's field in the serialized JSON? If so, you can use "omitempty" like you did in the other type. var boolField struct { Must []HasTermOrMatch `json:"must,omitempty"` MustNot []HasTermOrMatch `