I would suggest eliminating check_json_validity and doing the checks here.