Source: 📖 Python Cookbook ch6.2 p179
The json
module is used for working with JSON data. It's operation mirrors that of pickle
.
import json
data = {
'name': 'ACME'
'shares': 100,
'price': 542.23
}
with open('stocks.json', 'w') as f:
json.dump(data, f)
with open('stocks.json', 'r') as f:
data = json.load(f)