You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the spirit of the dump/dumps default= parameter, a similar default_key= could be specified for def _stringify_key(key):
For example, currently one may conveniently support UTC datetime as a dictionary value by:
def json_serial(obj):
"""JSON serializer for objects not serializable by default json code"""
if isinstance(obj, datetime.datetime):
serial = obj.isoformat()
return serial
raise TypeError("Type not serializable")
but _stringify_key fails when datetime is a dictionary key.
All of the same cautions would apply, of course, but at least someone who thought they knew what they were doing could get hurt their own way.
I hacked it w/
elif _use_decimal and isinstance(key, Decimal):
key = str(key)
# kcrossen ...
elif isinstance(key, datetime.datetime):
key = key.isoformat()
# ... kcrossen
elif _skipkeys:
key = None
else:
raise TypeError("key " + repr(key) + " is not a string")
return key
but it doesn't feel righteous somehow.
The text was updated successfully, but these errors were encountered:
In the spirit of the dump/dumps default= parameter, a similar default_key= could be specified for
def _stringify_key(key):
For example, currently one may conveniently support UTC datetime as a dictionary value by:
but _stringify_key fails when datetime is a dictionary key.
All of the same cautions would apply, of course, but at least someone who thought they knew what they were doing could get hurt their own way.
I hacked it w/
but it doesn't feel righteous somehow.
The text was updated successfully, but these errors were encountered: