summaryrefslogtreecommitdiffstats
path: root/utils/json.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/json.py')
-rw-r--r--utils/json.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/utils/json.py b/utils/json.py
new file mode 100644
index 0000000..05d66cb
--- /dev/null
+++ b/utils/json.py
@@ -0,0 +1,16 @@
1import json
2from json import JSONEncoder
3
4from pydantic import BaseModel
5
6
7class Encoder(JSONEncoder):
8 def default(self, o):
9 if isinstance(o, BaseModel):
10 return o.model_dump()
11
12 return super().default(o)
13
14
15def json_serializer(item: any):
16 return json.dumps(item, cls=Encoder)