In that case, how about using Array(returned_parameters['nodegroups'])? That way an array is always returned and you don't need the if