Created
August 17, 2023 17:35
-
-
Save JeffreyMFarley/23f23a263e88f198c0d514935961760f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date, datetime | |
from decimal import Decimal | |
def json_serial(obj): | |
"""Helps json.dumps render datetime objects""" | |
if isinstance(obj, date): | |
return obj.isoformat()[:10] | |
if isinstance(obj, datetime): | |
return obj.isoformat()[:10] | |
if isinstance(obj, Decimal): | |
return f'{obj.normalize():f}' | |
raise TypeError(f"Type {type(obj)} not serializable") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment