title: Using a custom JSON encoder for SQLAlchemy's PostgreSQL JSONB implementation
body: <p>I am using SQLAlchemy's core library to access some PostgreSQL database. Consider I have the following table:</p>
  
  <pre><code>create table foo (j jsonb);
  </code></pre>
  
  <p>And the following python code:</p>
  
  <pre><code>from decimal import *
  from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, DateTime
  from sqlalchemy.dialects.postgresql import JSONB
  metadata = MetaData(schema="public")
  foo = Table('foo', metadata,Column('f', JSONB))
  d = Decimal(2)
  ins = foo.insert().values(j = {'d': d})
  # assuming engine is a valid sqlalchemy's connection
  engine.execute(ins)
  </code></pre>
  
  <p>This last sentence fails with the following error:</p>
  
  <pre><code>StatementError("(builtins.TypeError) Decimal('2') is not JSON serializable",)
  </code></pre>
  
  <p>Which is why I am asking this question: Is there a way to specify a custom encoder for SQLAchemy to use when encoding json data into PostgreSQL dialect?</p>