Json.loads not working

‘function’ object has no attribute ‘loads’

import json
def json(url):
json_response=urlopen(url)
json_=json_response.read()
json_data=json.loads(json_)
print(type(json_data))
with open(“chuck_norris.csv”,“w”) as f:
if json_data[‘value’][‘jokes’]!=None:
z=(json_data[‘value’][‘joke’])
z+=’\n’
f.write(z)

Hi @fguglani,
Please change the name of your function. When you declare a function named “json”, you have over-written the module import. Now when you use json(), you are recursively calling your own function.
Change it to something like: json_custom or my_json.

Hope this helps!

Thankyou for the help

1 Like