I have code which contains some nested array values:
var descriptor models.Descriptor
_ = json.NewDecoder(r.Body).Decode(&descriptor)
result, _ := collectionDescriptor.InsertOne(context.TODO(), descriptor)
type Descriptor struct {
Id string `json:"id" bson:"id"`
Type string `json:"type,omitempty" bson:"type,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
Version string `json:"version,omitempty" bson:"version,omitempty"`
Modules []string `json:"modules,omitempty" bson:"modules,omitempty"`
Configs []Config `json:"configs" bson:"configs"`
}
type Config struct {
Id string `json:"id" bson:"id"`
Type string `json:"type,omitempty" bson:"type,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
Protocol []Protocols `json:"protocol" bson:"protocol"`
}
type Protocols struct {
Id string `json:"id" bson:"id"`
Type string `json:"type,omitempty" bson:"type,omitempty"`
Name string `json:"name" bson:"name,omitempty"`
Items []Itemes `json:"items" bson:"items"`
}
descriptor.Configs[0].Protocol[0] = nil
config = descriptor.Configs[0]
_ = json.NewDecoder(r.Body).Decode(&config)
conf, errr := collectionConfigDes.InsertOne(context.TODO(), config)
json.NewEncoder(w).Encode(conf)
I want to remove the value in descriptor.configs[0].protocol
to be an empty array or an empty string. which I will then send to MongoDB. JSON form like below