0

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)

Tal Avissar
  • 10,088
  • 6
  • 45
  • 70
  • 3
    This should answer your question - – Prashant Kumar Jan 21 '20 at 05:44
  • Minor point, but the term "saving" is a little weird here. Usually one may use the word saving for the reverse process where you want to serialize an object to json so it can be easily *saved* to a file, the reverse operation would be called de-serializing – Hymns For Disco Jan 21 '20 at 05:56
  • What’s wrong about a list? If you want to extract only emails, you end up with a list of emails. A dict would require some auxiliary information (as key or value) so you would not have just the emails as desired. – MisterMiyagi Jan 21 '20 at 06:24

1 Answers1

1

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']
Tal Avissar
  • 10,088
  • 6
  • 45
  • 70