Spaces:
Sleeping
Sleeping
File size: 430 Bytes
a3386d3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import json
from bson import ObjectId
from datetime import datetime
def custom_serializer(obj):
if isinstance(obj, ObjectId):
return str(obj)
if isinstance(obj, datetime):
return obj.isoformat() # Convert datetime to ISO 8601 format
raise TypeError(f"Object of type {type(obj)} is not JSON serializable")
def convert_to_json(data):
return json.dumps(data, default=custom_serializer, indent=4)
|