Skip to content

Commit

Permalink
Fail softly when can't parse json
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Nov 21, 2024
1 parent 6059827 commit 4645bd0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions template/startup_scripts/0002_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ def __call__(self, obj):
class E2BJSONFormatter(JSONFormatter):
def __call__(self, obj):
if isinstance(obj, (list, dict)):
return orjson.loads(
orjson.dumps(
obj, option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NON_STR_KEYS
)
), {"expanded": True}
try:
return orjson.loads(
orjson.dumps(
obj, option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NON_STR_KEYS
)
), {"expanded": True}
except TypeError:
pass

return super().__call__(obj)

Expand Down

0 comments on commit 4645bd0

Please sign in to comment.