Add toJSON method to collections