transforming JSON into patent child relation : I am tring to convert `JSON vm.scholasticlist` into `JSON vm.parentList2`.
In `JSON vm.scholasticlist`, ***s_gid*** is unique key, and ***parent_id*** point to parent ***s_gid***. 

I am trying following code, but unable to build it.

        vm.scholasticlist = [];
                vm.parentList = [];
                vm.parentList2 = [];
    
            for (var i in vm.scholasticlist) {
                if(vm.scholasticlist[i]['parent_id'] == 0 ){
                    vm.parentList.push(vm.scholasticlist[i])
                }
            }
    
            vm.parentList2 = vm.parentList;
    
            for (var i in vm.parentList) {
    
                console.log(vm.parentList[i]['s_gid'])
                for (var x in vm.scholasticlist) {
                    if(vm.scholasticlist[x]['parent_id'] === vm.parentList[i]['s_gid'] ){
                        console.log(vm.parentList[i]['s_gid'])
                        vm.parentList2.push(vm.scholasticlist[x])
                    }
                }
            }
    		
    
    vm.scholasticlist = [{
    	"s_gid": "10",
    	"m_s_p_id": "1",
    	"subject_group_name": "Foundation of Information Technology",
    	"parent_id": "0",
    	"sname": ""
    }, {
    	"s_gid": "11",
    	"m_s_p_id": "2",
    	"subject_group_name": "Life Skills",
    	"parent_id": "0",
    	"sname": ""
    }, {
    	"s_gid": "15",
    	"m_s_p_id": "2",
    	"subject_group_name": "Thinking Skills",
    	"parent_id": "11",
    	"sname": "Th.sk"
    }, {
    	"s_gid": "15",
    	"m_s_p_id": "2",
    	"subject_group_name": "Thinking Skills",
    	"parent_id": "11",
    	"sname": "Th.sk"
    }]

want to build new JSON with parent child relation


vm.parentList2 = [{
	"s_gid": "10",
	"m_s_p_id": "1",
	"subject_group_name": "Foundation of Information Technology",
	"parent_id": "0",
	"sname": ""
}, {
	"s_gid": "11",
	"m_s_p_id": "2",
	"subject_group_name": "Life Skills",
	"parent_id": "0",
	"sname": "",
	"child": [{
		"s_gid": "15",
		"m_s_p_id": "2",
		"subject_group_name": "Thinking Skills",
		"parent_id": "11",
		"sname": "Th.sk"
	}, {
		"s_gid": "15",
		"m_s_p_id": "2",
		"subject_group_name": "Thinking Skills",
		"parent_id": "11",
		"sname": "Th.sk"
	}]
}]




