avoid 500s on unsupported json requests and improve empty dataset code