Lesson 2 of 5 · 2 min
Reading JSON safely
Models reply with text. When you ask for JSON, you still have to check it, because a missing field or a string where you expected a number will break your program later and far away.
import json
reply = '{"name": "Asha", "score": "87", "skills": ["python"]}'
data = json.loads(reply)
print(data["name"], data["score"] + "3") # a string, not a number
Parsing succeeding does not mean the data is right.
