I have below jsons shown below :
json1=
{
'201801': 58,
'201802': 74,
careerLevel: 'Analyst',
careerLevels: [{
'201801': 29,
'201802': 37,
careerID: '10000100'
},
{
'201801': 29,
'201802': 37,
careerID: '10000110'
}
]
}
json2 =
{
'201801': 58,
'201802': 74,
careerLevel: 'Consultant',
careerLevels: [{
'201801': 29,
'201802': 37,
careerID: '10000100'
},
{
'201801': 29,
'201802': 37,
careerID: '10000110'
}
]
}
And in result i need to merge them dynamically so that they should look like below :
result=
careerLevelGroups: [{
'201801': 58,
'201802': 74,
careerLevel: 'Analyst',
careerLevels: [{
'201801': 29,
'201802': 37,
careerID: '10000100'
},
{
'201801': 29,
'201802': 37,
careerID: '10000110'
}
]
},
{
'201801': 58,
'201802': 74,
careerLevel: 'Consultant',
careerLevels: [{
'201801': 29,
'201802': 37,
careerID: '10000100'
},
{
'201801': 29,
'201802': 37,
careerID: '10000110'
}
]
}
]
Like the above there will be more jsons of same format so i think i need some loop with which i can directly attach all of them. I have tried :
jsonMap = new TSMap();
jsonMap.set("careerLevelGroups",[]);
jsonMap.toJson().concat( json1.concat(json2)); // this is not giving me right answer
I think i need some loop as i need to add all of them dynamically.