+ 1
How to work with json using python ?
2 Respostas
+ 5
Here is another sample, it gets the json from an api on internet.
import requests
import json
r = requests.get('https://moppenbot.nl/api/random/')
#print(r.text)
r_dict = json.loads(r.text)
print(r_dict['joke']['joke'])
+ 1
I usually do this whenever I need to read a json file:
data = {}
with open("file.json", "r") as f:
try:
data = json.load(f)
except:
print("an error happened")
print(data)
print(data["someKey"])