summaryrefslogtreecommitdiff
path: root/lib/utils/json.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/json.py')
-rw-r--r--lib/utils/json.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/utils/json.py b/lib/utils/json.py
new file mode 100644
index 00000000..c670a46b
--- /dev/null
+++ b/lib/utils/json.py
@@ -0,0 +1,15 @@
+from flask.json import JSONEncoder
+
+
+class InkStitchJSONEncoder(JSONEncoder):
+ """JSON encoder class that runs __json__ on an object if available.
+
+ The __json__ method should return a JSON-compatible representation of the
+ object.
+ """
+
+ def default(self, obj):
+ try:
+ return obj.__json__()
+ except AttributeError:
+ return JSONEncoder.default(self, obj)