Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit 67dad89

Browse files
committed
Some slight error handling for converting unknown objects to json
1 parent 5e75b6a commit 67dad89

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/pythonjsonlogger/jsonlogger.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ def default(self, obj):
5858
or type(obj) == type:
5959
return str(obj)
6060

61-
return super(JsonEncoder, self).default(obj)
61+
try:
62+
return super(JsonEncoder, self).default(obj)
63+
64+
except TypeError:
65+
try:
66+
return str(obj)
67+
68+
except Exception:
69+
return None
6270

6371
def format_datetime_obj(self, obj):
6472
return obj.isoformat()

0 commit comments

Comments
 (0)