github.com/traefik/yaegi@v0.15.1/_test/struct23.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "os" 6 ) 7 8 type S struct { 9 Name string 10 Child []*S 11 } 12 13 func main() { 14 a := S{Name: "hello"} 15 a.Child = append(a.Child, &S{Name: "world"}) 16 json.NewEncoder(os.Stdout).Encode(a) 17 a.Child[0].Child = append([]*S{}, &S{Name: "sunshine"}) 18 json.NewEncoder(os.Stdout).Encode(a) 19 } 20 21 // Output: 22 // {"Name":"hello","Child":[{"Name":"world","Child":null}]} 23 // {"Name":"hello","Child":[{"Name":"world","Child":[{"Name":"sunshine","Child":null}]}]}