Skip to content

Base serializers

python_type_to_json_type(value)

Convert a Python type to a JSON type.

Source code in light_agents/serializers/tools/base_serializers.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def python_type_to_json_type(value: Any) -> str:
    """Convert a Python type to a JSON type."""
    if isinstance(value, str):
        return "string"
    elif isinstance(value, (int, float)):
        return "number"
    elif isinstance(value, bool):
        return "boolean"
    elif isinstance(value, (list, tuple)):
        return "array"
    elif isinstance(value, dict):
        return "object"
    elif isinstance(value, Enum):
        return "enum"
    elif value is None:
        return "null"
    else:
        return "string"