Added a validation to check if object is array in flatten.