I'm trying to load a rather large JSON file that has x amount of JSON arrays. The issue I'm having is the fact that the each node in the data below has a unique name, so I'm not sure how to build the struct to store them.
Here is snippet of the data from the JSON file (This file can have many more nodes that just two below)
{
"timestamp": 1533397325,
"total_nodes": 9522,
"latest_height": 535196,
"nodes": {
"220.75.229.130:3927": [
70015,
"/Satoshi:0.13.2/",
1530858117,
13,
165277,
"220.75.229.130",
"Seoul",
"KR",
37.5985,
126.9783,
"Asia/Seoul",
"AS4766",
"Korea Telecom"
],
"192.162.102.68:8333": [
70015,
"/Satoshi:0.15.1/",
1533061934,
13,
535196,
"192.162.102.68",
null,
"RU",
55.7386,
37.6068,
null,
"AS50113",
"MediaServicePlus LLC"
]
}
}
So far, this is my code, and JSON objects in Go:
type MyJsonName struct {
LatestHeight int `json:"latest_height"`
Timestamp int `json:"timestamp"`
TotalNodes int `json:"total_nodes"`
Nodes struct {
Data string
} `json:"nodes"`
}
func main() {
jsonFile, err := os.Open("someFile")
if err != nil {
fmt.Println(err)
}
byteValue, _ := ioutil.ReadAll(jsonFile)
var MyJSONANE MyJsonName
err = json.Unmarshal(byteValue, &MyJSONANE)
if err != nil {
fmt.Println(err)
}
fmt.Println(MyJSONANE)
}
This code works great, my issue is the fact that Data in nodes in never populated with the JSON arrays and their contents.
This is the output: {535196 1533397325 9522 {}}
Any help adjusting my struct to read in the JSON arrays will be greatly appreciated. I would just like to draw emphasis to the names of the JSON arrays in nodes being unique, and there can be total_nodes
amount of them.