I have this json file:
{
"entityId": "12345",
"displayName": "hostabc",
"toRelationships": {
"isProcessOf": [
{
"id": "proce123D00BB86",
"type": "PROCESS_GROUP_INSTANCE"
},
{
"id": "proc678DD0DBA4",
"type": "PROCESS_GROUP_INSTANCE"
},
{
"id": "proc978DD0DBA4",
"type": "PROCESS_GROUP_INSTANCE"
}
]
}
}
I need to extract id fields under isProcessOf and build a data list.
I am new to python, how would I do this?
>Solution :
Looks like a list comprehension would do the job. You access dictionary values by its keys, so since you want to access 'id's of dictionaries in a list under the 'isProcessOf' key, which in turn is under the 'toRelationships' key, you can do it as:
out = [d['id'] for d in dct['toRelationships']['isProcessOf']]
Output:
['proce123D00BB86', 'proc678DD0DBA4', 'proc978DD0DBA4']