Make CSV and JSON processing compatible with merge of master

Also use new Flask-SQLAlchemy 2.0 behaviour.
Make JSON and CSV creation match the master branch versions.