I am using an API to get JSON data from an external source and am not sure how to get particular elements from the JSON.
json_data = json.loads(resp.text) #resp.text is the response from the API call
print(json_data)
Prints the following (the raw output is single line/flat, so I have formatted to make it more readable):
[
{'version': {
'rowVersion': 2044},
'name': 'Administrator',
'permissions': [
{'path': 'Activity/Cancel All', 'name': 'Activity/Cancel All'},
{'path': 'Activity/View All', 'name': 'Activity/View All'},
{'path': 'Audit Log/Edit', 'name': 'Audit Log/Edit'},
{'path': 'Audit Log/View', 'name': 'Audit Log/View'}
],
'id': 1,
'permissionPaths': ['Activity/Cancel All', 'Activity/View All', 'Audit Log/Edit', 'Audit Log/View'],
'displayName': 'Administrator'
},
{'version': {
'rowVersion': 964033},
'name': 'ViewOnly',
'permissions': [
{'path': 'Activity/View All', 'name': 'Activity/View All'},
{'path': 'Audit Log/View', 'name': 'Audit Log/View'},
],
'id': 4,
'permissionPaths': ['Activity/View All', 'Audit Log/View']
'displayName': 'ViewOnly'
}
]
The following
for ROLES in json_data:
print(str(ROLES["name"]))
Prints:
Administrator
ViewOnly
So far, so good... However, I would like the output to be the role and permission name along the lines of...
Administrator, Activity/Cancel All
Administrator, Activity/View All
Administrator, Audit Log/Edit
Administrator, Audit Log/View
ViewOnly, Activity/View All
ViewOnly, Audit Log/View
Please let me know how I can achieve this in Python. Thanks!