I have a json that is coming from the server similar to this (with multiple nested json objects).
{
"employee": [{
"fullname": {
"firstname": "abcd",
"lastname": "defg"
},
"project": [{
"projectname":"abcd_1",
"datejoined": "2019-06-18T01:29:38.6013262+00:00",
"projectmanager": "abcdM1",
}, {
"projectname":"abcd_2",
"datejoined": "2018-06-18T01:29:38.6013262+00:00",
"projectmanager": "abcdM2",
}, {
"projectname":"abcd_3",
"datejoined": "2017-06-18T01:29:38.6013262+00:00",
"projectmanager": "abcdM3",
}
]
},{
"fullname": {
"firstname": "abcd",
"lastname": "defg"
},
"project": [{
"projectname":"abcd_1",
"datejoined": "2019-06-18T01:29:38.6013262+00:00",
"projectmanager": "abcdM1",
}, {
"projectname":"abcd_2",
"datejoined": "2018-06-18T01:29:38.6013262+00:00",
"projectmanager": "abcdM2",
}, {
"projectname":"abcd_3",
"datejoined": "2017-06-18T01:29:38.6013262+00:00",
"projectmanager": "abcdM3",
}
]
}
]
}
The service component will send only the relevant data in a reduced json format to the UX.
I want to extract employee.fullname.firstname and employee.project.projectname.
The output should be
{
"employee": [{
"fullname": {
"firstname": "abcd",
},
"project": [{
"projectname":"abcd_1",
}, {
"projectname":"abcd_2",
}, {
"projectname":"abcd_3",
}
]
},{
"fullname": {
"firstname": "abcd",
},
"project": [{
"projectname":"abcd_1",
}, {
"projectname":"abcd_2",
}, {
"projectname":"abcd_3",
}
]
}
]
}
I flattened the Json but it gives the tags as employee.0.fullname.firstname and employee.0.project.0.projectname etc
What is the best way to extract with/without flattening?