Using JSON Type with Flask-sqlalchemy & Postgresql Using JSON Type with Flask-sqlalchemy & Postgresql flask flask

Using JSON Type with Flask-sqlalchemy & Postgresql


Looking at the SQLAlchemy documentation for the JSON data type it appears that you should be able to use the .cast method:

from sqlalchemy.types import Integerfrom app import app, dbfrom models import Target # SQLAlchemy 1.1+data = Target.query.order_by(Target.product['salesrank'].astext.cast(Integer))# SQLAlchemy < 1data = Target.query.order_by(Target.product['salesrank'].cast(Integer))