Answer the question
In order to leave comments, you need to log in
Creating a map[string]interface array and adding json files from different sources there?
The bottom line is that I have a loop that reads all json files from directories (they are all from different files). And I need to add all the read files to different map intefaces in order to compare fields in the future. Can you suggest how to do this? At the moment, I was able to create only 1 map interface, but I cannot compare json file fields inside it.
var master map[string]interface{}
//var result map[string]interface{}
func main() {
fileIndex := 3 // three json files. All named test1.json, test2.json and test3.json
for i := 1; i <= fileIndex; i++ {
fileName := fmt.Sprintf("%s%d%s", "test", i, ".json")
// Open jsonFile
jsonFile, err := os.Open(fileName)
if err != nil {
log.Println("Error:", err)
}
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &master)
fmt.Println(master)
}
{
"name":"Kate",
"date":"2013-04-23T19:24:59.511Z",
"data":"is nice"
}
{
"name":"Gleison",
"date":"2012-04-23T19:25:00.511Z",
"data":"is a good person"
}
{
"name":"Rodrigo",
"date":"2013-04-23T20:24:59.511Z",
"data":"is kind"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question