In your example you need to allocate space for Person slice because slices are not arrays. They are just like pointers, but with length and capacity parameters You better define Person as separate type, then add it to your main structure like this:
type PhoneNumber struct {
Carrier string `json:"carrier"`
Number string `json:"number"`
}
type Person struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
PhoneNumbers []PhoneNumber `json:"phoneNumber"`
}
type example struct {
Example string `json:"example"`
Persons []Person `json:"persons"`
}
func main() {
ex := example{
Example: "example",
Persons: []Person{
Person{
FirstName: "JHON",
LastName: "DOE",
MiddleName: "TEST",
PhoneNumbers: []PhoneNumber{
PhoneNumber{
Carrier: "AT&T",
Number: "123545568",
},
},
},
},
}
fmt.Println(ex)
}