Implement proper toJSON for collections