What im doing wrong? I tried tons of way but i get always empty array. Here is my code:
type Switches struct {
switches []SwitchInfo
}
type SwitchInfo struct {
IP string
Community string
}
func main() {
file, e := ioutil.ReadFile("./config.json")
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
fmt.Printf("%s\n", file)
var jsonObject Switches
err := json.Unmarshal(file, &jsonObject)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Results: %v\n", jsonObject)
}
And this is my json file
{"switches":
[
{
"IP" : "1.1.1.1",
"Community" : "asdfg"
},
{
"IP" :"1.1.1.1",
"Community" : "asdf"
}
]
}
I checked my json file it is valid. I think i have problem with my structs. Ty for your help.