I have the following in my json array (conf.json file).
{
"Repos": [
"a",
"b",
"c"
]
}
I am attempting to read this json and then iterate over it but get stuck. I am very new to go (and to programming) so I am having a hard time understanding what is happening here.
import (
"encoding/json"
"fmt"
"os"
)
type Configuration struct {
Repos []string
}
func read_config() {
file, _ := os.Open("conf.json")
decoder := json.NewDecoder(file)
configuration := Configuration{}
err := decoder.Decode(&configuration)
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(configuration.Repos)
}
[a, b, c]
What I would like to do is be able to iterate over the array and split out each value individually but have not had any luck at doing this. Am I taking the wrong approach to this? Is there a better way to do this?