SyntaxStudy
Sign Up
Python Beginner 3 min read

JSON Type Mapping

Type Mapping

JSON has six types. Python maps them automatically on encode and decode.

Example
# 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
Pro Tip

JSON numbers without decimals become int; with decimals become float — be explicit in schemas.