Convert sorted arrays to objects where possible