Module 3: Functions and modules · 8 min
Working with JSON
JSON is a text format for data that looks like Python dictionaries and lists. Web services and AI services send and receive it all the time.
import json
text = '{"city": "Lahore", "temp": 31}'
data = json.loads(text) # text -> dictionary
print(data["temp"]) # 31
back = json.dumps(data) # dictionary -> text
print(back)
loads and dumps work with text in memory. load and dump work with files.