
Predict
JSON Shapes
json.loads(text) turns JSON text into Python objects, and
json.dumps(obj) goes the other way. The mapping:
| JSON | Python |
|---|---|
object {...} |
dict |
array [...] |
list |
true / false |
True / False |
null |
None |
Nested data is just dicts inside lists inside dicts, index step by step.
import json
raw = '''{"ship": "Wren", "crew": [
{"name": "Ada", "lit": true},
{"name": "Bo", "lit": null}]}'''
data = json.loads(raw)
crew = data["crew"]
print(crew[1]["lit"], len(crew), type(crew[0]).__name__)