Intermediate·5 min·intermediate · data
JSON
JSON
JSON is how systems exchange data. Python's json module converts both ways.
The two calls
json.dumps(obj, indent=2)— Python → JSON stringjson.loads(text)— JSON string → Python
Type mapping
| Python | JSON |
|---|---|
| dict | object |
| list, tuple | array |
| str | string |
| int, float | number |
| True, False | true, false |
| None | null |
Try it
- Parse
'{"a": 1, "b": [2, 3]}'and printb's sum. - Serialize
{"date": datetime.date.today()}— what error do you get? Why?