13 lines
351 B
Python
13 lines
351 B
Python
import json
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
|
|
def json_serializer(obj: Any) -> str:
|
|
def default(o: Any):
|
|
if isinstance(o, datetime):
|
|
return o.isoformat()
|
|
raise TypeError(f"Object of type {type(o).__name__} is not JSON serializable")
|
|
|
|
return json.dumps(obj, default=default, ensure_ascii=False)
|