Move json response rendering to middleware