JSON text can be converted to Python dictionaries and lists.
JSON is a common text format for structured data. json.loads() parses JSON text into Python data; json.dumps() creates JSON text from Python data.
import json
student_json = '{"name": "Ana", "score": 95}'
student = json.loads(student_json)
print(student["name"])
result = json.dumps(student)
print(result)student_json is text, while student is a Python dictionary after loads(). dumps() makes JSON text again.
Ana
{"name": "Ana", "score": 95}Change one value, then explain how the resulting data changes.
Keep this in mind: Follow each data operation in order before predicting the result.
import json
student_json = '{"name": "Ana", "score": 95}'
student = json.loads(student_json)
print(student["name"])
student["score"] += 5
print(json.dumps(student))
# Change the JSON text or read another keyRun the example, then change one value and observe the result.
