Restructure javascript objects