Type Mapping
JSON has six types. Python maps them automatically on encode and decode.
JSON has six types. Python maps them automatically on encode and decode.
# JSON → Python mapping:
# object → dict
# array → list
# string → str
# number → int or float
# true/false → True/False
# null → None
import json
data = json.loads('{"active":true,"score":9.5,"note":null,"tags":["a","b"]}')
print(type(data["active"])) # bool
print(type(data["score"])) # float
print(data["note"] is None) # True
JSON numbers without decimals become int; with decimals become float — be explicit in schemas.