I have a JSON object and was wondering how I can iterate over the object to pull values for \"id\".
{
\"totalSize\": 5,
\"done\": true,
\"records\": [
{
s = """{ "totalSize": 5,
"done": true, "records": [
{ "attributes": {
"type": "EventLogFile",
"url": "/services/data/v38.0/sobjects/EventLogFile/0AT1U000003kk7dWAA" },
"Id": "0AT1U000003kk7dWAA" }
]
}"""
s = json.loads(s)
[r['Id'] for r in s['records']]
['0AT1U000003kk7dWAA']
You can iterate through the records
key as a list and then access the Id
key of each sub-dict:
for i in s["records"]:
print(i['Id'])