Fix for MAGN-3399

The protection needs to be applies inside the loop to protect against nested empty arrays