handle nested arrays for primitives and objects