I have a json file with an object with multiple nested arrays and objects and I have trouble finding a way to iterate through it and get all the data as properties are nested in various 'locations' inside the object. I tried to simplify the object and hope its not too large:
{
"trips": [{
"trains": {
"originTrains": {
"originTrain": [{
//always 2 x trainSegment - 1 for train to location and return train
"trainSegment": [{
//unknown numbers of objects inside trainSegment array
"Departure": {
"Location": "xxx"
},
"Arrival": {
"Location": "yyy"
},
"duration": 195,
}, {
"Departure": {
"Location": "yyy"
},
"Arrival": {
"Location": "zzz"
},
"duration": 240,
}],
"duration": 485
}, {
"trainSegment": [{
"Departure": {
"Location": "zzz"
},
"Arrival": {
"Location": "mmm"
},
"duration": 160,
}, {
"Departure": {
"Location": "mmm"
},
"Arrival": {
"Location": "xxx"
},
"duration": 325,
}],
"duration": 745
}]
},
"Direction": "Return"
},
"PriceInfo": {
"Breakdown": {
"FareBreakdown": {
"PassengerQuantity": {
"Quantity": 1,
"Code": "ABC"
},
"Endorsements": {
"NotRefundable": true
}
}
},
"FareInfos": {
"FareInfo": [{
"Extensions": {
"SeatsRemaining": {
"BelowMinimum": false,
"Number": 4
}
}
}]
},
"Fare": {
"TotalFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": 341.61
},
"Taxes": {
"Tax": [{
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"TaxCode": "TOTALTAX",
"Amount": 66.25
}]
},
"BaseFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": 275.36
}
}
},
"TicketingInfo": {
"TicketType": "eTicket"
}
}, {
"trains": {
"originTrains": {
//all over again
}
Eventually I want to display all the info (as origin, destination,time, duration for all trains. Anything I tried so far didn't really work. I didn't provide my code as all my loops don't make sense and didn't work, but could provide of course. Any help would be very much appreciated. Thank you.