Hi,
Need help please in counting the number of times the key source appears in the file.
I need to change the names of the keys name and value so I need to know how many times to loop through the json file.
Below is a sample of the json file I received and one of the many things I tried.
with open(r’C:\Users\Administrator\Documents\rajson.json’) as f:
jsonObj = json.load(f)print(jsonObj[1])
key_source = [k['data'] for k in jsonObj[1] if k.get('source')] print('len: ', len(key_source))
{ "timestamp": "2022-09-20T08:16:00.000Z", "metadata": { "orgID": "6780", "projectId": 0988, } }, { "data": "workers": [ { "identifiers": { "FullName": null, "NINumber": null, "CompID": null }, "lastName": null, "costCenter": null }, { "codes": [ { "source": { "name": "net_salary", "value": 11500 }, "name": "net_salary", "code": "rt_sa", "value": 11500 }, { "identifiers": { "FullName": null, "NINumber": null, "Comp ID": null }, "lastName": null, "costCenter": null }, { "codes": [ { "source": { "name": "hiredate", "value": 3.333 }, "name": "hiredate", "code": "h_code", "value": 3.333 },
Thank you