I have a list made of responses to an API request. The result is the JSON with a lot of nested dictionaries and lists like this:
{'Siri': {'ServiceDelivery': {'ResponseTimestamp': '2020-12-13T08:16:31Z',
'ProducerRef': 'IVTR_HET',
'ResponseMessageIdentifier': 'IVTR_HET:ResponseMessage::df80db10-3cd3-4d8d-9cee-27ec6c716630:LOC:',
'StopMonitoringDelivery': [{'ResponseTimestamp': '2020-12-13T08:16:31Z',
'Version': '2.0',
'Status': 'true',
'MonitoredStopVisit': [{'RecordedAtTime': '2020-12-13T08:16:27.623Z',
'ItemIdentifier': 'RATP:Item::STIF.StopPoint.Q.40944.A.7:LOC',
'MonitoringRef': {'value': 'STIF:StopPoint:Q:40944:'},
'MonitoredVehicleJourney': {'lineRef': {'value': 'STIF:Line::C01742:'},
'framedVehicleJourneyRef': {'dataFrameRef': {'value': 'any'},
'datedVehicleJourneyRef': 'RATP:VehicleJourney::RA.A.0916.1:LOC'},
'journeyPatternName': {'value': 'TEDI'},
'vehicleMode': [],
'publishedLineName': [{'value': 'St-Germain-en-Laye. Poissy. Cergy. / Boissy-St-Léger. Marne-la-Vallée.'}],
'directionName': [{'value': 'St-Germain-en-Laye. Poissy. Cergy.'}],
'serviceFeatureRef': [],
'vehicleFeatureRef': [],
'originName': [],
'originShortName': [],
'destinationDisplayAtOrigin': [],
'via': [],
'destinationRef': {'value': 'STIF:StopPoint:Q:411359:'},
'destinationName': [{'value': 'Poissy'}],
'destinationShortName': [],
'originDisplayAtDestination': [],
'vehicleJourneyName': [],
'journeyNote': [{'value': 'TEDI'}],
'facilityConditionElement': [],
'situationRef': [],
'monitored': True,
'monitoringError': [],
'progressStatus': [],
'trainBlockPart': [],
'additionalVehicleJourneyRef': [],
'monitoredCall': {'stopPointRef': {'value': 'STIF:StopPoint:Q:40944:'},
'stopPointName': [{'value': 'Torcy'}],
'vehicleAtStop': True,
'originDisplay': [],
'destinationDisplay': [],
'callNote': [],
'facilityConditionElement': [],
'situationRef': [],
'arrivalOperatorRefs': [],
'expectedDepartureTime': '2020-12-13T08:16:00Z',
'departurePlatformName': {'value': '2'},
'departureOperatorRefs': []}}},
I need an efficient way to extract the value pairs corresponding to, for example, the expectedDepartureTime
key that's lying somewhere hidden in that maze of nested dictionaries. It has to be efficient because the formatting from the source site isn't very stable so different stations (it's transit data) will have different keys for the same value, e.g. ExpectedDepartureTime
or expecteddepartureTime
and I might need to try a lot of different things.
P.S.: I tried the solution by @hexerei software here Find all occurrences of a key in nested dictionaries and lists but it just gave me a
<generator object gen_dict_extract at 0x00000200632C8948>
as the output. How do I get the values out of this?