My goal is to identify which instanse is dict
, str
or list
under the items
hierarchy.
def flatten(data):
for i, item in enumerate(data['_embedded']['items']):
if isinstance(item, dict):
print('Item', i, 'is a dict')
elif isinstance(item, list):
print('Item', i, 'is a list')
elif isinstance(item, str):
print('Item', i, 'is a str')
else:
print('Item', i, 'is unknown')
flatten(data)
Output of this code is:
Item 0 is a dict
Item 1 is a dict
Item 2 is a dict
Item 3 is a dict
Item 4 is a dict
Desired out put should access the keys (identifier
, enabled
,family
) inside the 0
, 1
etc.
for a better udnerstnading of the structure of the JSON file please see the image