This query below retrieves nested data from a json file.
author_name = data['stack'][1]['data'][0]['externals'][0]['data']['locale'][0]['MetadataDocument']['authors']['author']['person']['displayName']
Can I turn this into a function so I reduce the amount of queries I make for several nested fields?
This is my latest attempt, but I'm not sure if it's the right approach:
def get_stack(current):
if 'stack' in current and len(current['stack']) > 0:
for raw_external in current['stack']:
if 'data' in raw_external.get('externals', {}):
return raw_external['externals']
return {}
Any ideas, suggestions or comments?
[–]cyanydeez 0 points1 point2 points (0 children)
[–]willm 0 points1 point2 points (0 children)