I want to create a structure like below
{
"acc_id" : [1, 2, 3, 4],
"acc_info" : [
{
"name": "abc"
},
{
"name": "pqr"
}
]
}
I have one list which should populate acc_id
and one set which should populate acc_info
.
I am very new to go, but trying to create a static variable for this structure but struggling.
tried to create something like this but I know it's not correct.
result := make(map[string][]map[string]string)
can anyone help me on this?
I find this question but not helpful : Create a Golang map of Lists
Refer golang blog post for more information.
package main
import (
"encoding/json"
"fmt"
"log"
)
type accountInfo struct {
AccID []int `json:"acc_id"`
AccInfo []map[string]string `json:"acc_info"`
}
func main() {
t := accountInfo{
AccID: []int{1, 2, 3, 4},
AccInfo: []map[string]string{
map[string]string{"name": "abc"},
map[string]string{"name": "pqr"},
},
}
res, err := json.Marshal(t)
if err != nil {
log.Println(err)
}
fmt.Println(string(res))
}