Reputation: 49
I am new to python and I need to extract only the email to JSON format from an API output.
example: 'email':'brucelee@.....' Currently I have my code appending to a list mainly because I am struggling to output to a Dictionary or something that I can use. Thanks in advance for any help!
{'account_locked': None,
'activated': None,
'addresses': None,
'allow_public_key': None,
'attributes': None,
'bad_login_attempts': None,
'company': None,
'cost_center': None,
'created': None,
'department': None,
'description': None,
'displayname': None,
'email': 'adasda@asdasda'}
moto = []
def make_api_call(id):
api_instance = jcapiv1.SystemusersApi(jcapiv1.ApiClient(configuration))
id = id
content_type = 'application/json' # str | (default to application/json)
accept = 'application/json' # str | (default to application/json)
fields = 'email firstname lastname username ' # str | Use a space seperated string of field parameters to include the data in the response. If omitted, the default list of fields will be returned. (optional) (default to )
filter = 'none' # str | A filter to apply to the query. (optional)
x_org_id = '' # str | (optional) (default to )
api_response1 = api_instance.systemusers_get(id, content_type, accept, fields=fields, filter=filter, x_org_id=x_org_id)
str(api_response1)
moto.append(api_response1)
for id in all_ids:
make_api_call(id)
print(moto)
Upvotes: 0
Views: 52
Reputation: 10304
all you need to do to get the email is:
api_response1 = api_instance.systemusers_get(id, content_type, accept, fields=fields, filter=filter, x_org_id=x_org_id)
import json
jsondata = json.loads(api_response1)
email = jsondata['email']
Upvotes: 1