github jpadilla/pyjwt 0.3.2
v0.3.2

latest releases: 2.4.0, 2.3.0, 2.2.0...
9 years ago

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)

Don't miss a new pyjwt release

NewReleases is sending notifications on new releases.