form json pkg you can encoding and decoding JSON format
package main
import (
"encoding/json"
"fmt"
)
type Species struct {
Human []Info `json:"human"`
Animal []Info `json:"animal"`
}
type Info struct {
Name string `json:"name"`
Number string `json:"number"`
}
func main() {
data := Species{
Human: []Info{
Info{Name: "dave", Number: "00001"},
Info{Name: "jack", Number: "00002"},
},
Animal: []Info{
Info{Name: "ko", Number: "00004"},
Info{Name: "na", Number: "00005"},
},
}
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(string(b))
}
solved How to put data in a struct with Golang?