I have an array that looks like:
item = [{'name': 'first'}, {'name': 'second', 'something': 'something4'}, {'name': 'third', 'hu': 'g'}]
I want to write a function that given a key it will return the json that contains the key. For example: by for first it will return {'name': 'first'} for third it will return {'name': 'third', 'hu': 'g'}
This is what I wrote so far
def func(obj, val_to_search , key_to_search):
j = json.loads(item)
for item in j:
if j[key_to_search] = val_to_search
return j
func(obj=item, val_to_search='first', key_to_search='name')
but this doesn't work. What am I doing wrong?