Pass json and csv through middleware

Fixes #1493 on github