throw exception if json_encode fails