summaryrefslogtreecommitdiff
path: root/lib/utils/json.py
blob: c670a46b273eb75b026e72016106cfc2696fc335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)