Skip to content

v0.3.2

Compare
Choose a tag to compare
@jpadilla jpadilla released this 13 Dec 22:31
· 778 commits to master since this release

Allow using a custom JSON encoder in jwt.encode()

PR #49 by @defyrlt
Ref #37

Example

import json
import decimal
import jwt


class CustomJSONEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, decimal.Decimal):
            return float(o)
        return super(CustomJSONEncoder, self).default(o)

data = {
    'some_decimal': decimal.Decimal('2.2')
}

token = jwt.encode(data, 'secret', json_encoder=CustomJSONEncoder)