I am using SQLAlchemy\'s core library to access some PostgreSQL database. Consider I have the following table:
create table foo (j jsonb);
This is supported via the json_serializer
keyword argument to create_engine
, as documented under sqlalchemy.dialects.postgresql.JSON:
def _default(val):
if isinstance(val, Decimal):
return str(val)
raise TypeError()
def dumps(d):
return json.dumps(d, default=_default)
engine = create_engine(..., json_serializer=dumps)