I am fairly new to Python and have been working on trying to print out the values attached to a key which is present in a nested list of dictionaries in a JSON. Here is the structure from what I can tell:
details - List of dicts
scorecardDetails - List of dicts
scorecard - Dict
playerHandicap - Key:Value
It is also worth noting there is another list called 'summary' at the same level as 'details'.
This is where I am at currently, but am struggling to work out how to identify that I only want to look at the 'playerHandicap' key:
details_list = json_load['details']
for index in range(len(details_list)):
for key in details_list[index]:
print(details_list[index][key])
Here is a snapshot of the JSON (the key/value pair required is in the 'scorecard' dict which there is multiple of):
"details":[
{
"startTime":"2021-03-16T12:16:16.000Z",
"formattedStartTime":"2021-03-16T12:16:16Z",
"scorecardDetails":[
{
"scorecard":{
"id":172482642,
"customerId":"******",
"playerProfileId":*****,
"roundPlayerName":"*******",
"connectDisplayName":"********",
"courseGlobalId":21042,
"courseSnapshotId":43716,
"frontNineGlobalCourseId":21042,
"scoreType":"STROKE_PLAY",
"useHandicapScoring":true,
"useStrokeCounting":false,
"startTime":"2021-03-16T12:16:16.000Z",
"formattedStartTime":"2021-03-16T12:16:16Z",
"endTime":"2021-04-23T09:09:47.000Z",
"formattedEndTime":"2021-04-23T09:09:47Z",
"unitId":"1",
"roundType":"ALL",
"inProgress":false,
"excludeFromStats":false,
"holesCompleted":18,
"publicRound":false,
"score":29,
"playerHandicap":0,
"courseHandicapStr":"061018120208141604010709111517031305",
"teeBox":"null",
"handicapType":"MEN",
"teeBoxRating":73.03,
"teeBoxSlope":118,
"lastModifiedDt":"2021-04-23T09:09:46.000Z",
"sensorOnPutter":false,
"handicappedStrokes":101,
"strokes":101,
I'm sure it's an easy solution but struggling to get my head around the different levels of looping! Thanks :)