adding logic for formatListFinal so it can handle objects or arrays