Changed writeJSON to JSONResponse and added a status code argument