File size: 403 Bytes
5b6f681
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import json
from typing import Any


def to_json_serializable(obj: Any) -> Any:
    """Try to convert common non-serializable objects into JSON-serializable forms.

    For now this is a simple wrapper around json.dumps for known simple cases.
    """
    try:
        json.dumps(obj)
        return obj
    except TypeError:
        # Fallback: convert to string representation
        return str(obj)