I am trying to iterate through a json response to get the elements for each array element in the response and add those to a new json object. I am making multiple calls that get a new json response, but also could return the same id from a previous call. I want to loop through all of the calls and have a list of unique id the end.
example json response
[{"firstName" : "John",
"lastName" : "Doe",
"id:" : "123542"
},
{"firstName" : "Jane",
"lastName" : "Doe",
"id:" : "123"
},
{"firstName" : "Harry",
"lastName" : "dude",
"id:" : "653"
}
]
What I have right now but doesn't remove the dups. It just adds every single
new_members = []
for team in teams
if team["name"] == "example":
members = call_to_get_members.json()
for member in members:
new_member = {"firstName": member["firstName"], "lastName": member["lastName"]}
if member not in new_members:
new_members.append(new_member)
break
dicts are not hashable, so can not be placed in a set. The OP would need to use tuples.call_to_get_membersbefore so I think this is an assignment.