I have:
def decoder(o):
return o.get("fruits")
array = '{"fruits": [{"apple": "red"}, {"banana": "yellow"}, "orange"]}'
data = json.loads(array, object_hook=decoder)
print(data)
This is returning [None, None, 'orange'].
However, if I do something like below without using object_hook
n = json.loads(array)
print(n.get("fruits"))
This returns [{'apple': 'red'}, {'banana': 'yellow'}, 'orange'] as desired.
How can I use object_hook to return [{'apple': 'red'}, {'banana': 'yellow'}, 'orange'] instead of [None, None, 'orange']? What part of my code is causing it to return None?