So I am trying to parse a json into some structs and that works ok with the following:
type train struct {
ID string `json:"id"`
Price float64 `json:"price,string"`
Distance float64 `json:"Distance,string"`
}
type Station struct {
ID int64 `json:"id,string"`
arrTrain []train`json:"arr"`
depTrain []train`json:"dep"`
}
The problem, however, is that I would like to easily be able to reference the items in arrTrain and depTrain using their ID, so I think I need to change the Station struct to have arrTrain and depTrain as maps with the ID as the key. Is this possible when parsing the json or does it have to be 'post-processed'?
EDIT: As stated in one of the comments, unfortunately my json is in the following form:
{
"id":1,
"arr": [
{"id":"one","price":"$10.1","Distance":"100km"},
{...}
],
"dep":[
{"id":"one","price":"$10.1","Distance":"100km"},
{...}
]
}
In other words the ID is not on the outside of the json object and arrTrain is list.