I am trying to iterate over array of objects and remove duplicate entries while pushing to new array if any duplicates in nested array and form a flat array with same key value pair by just removing duplicate key. Can any one help please with below data set.
Json sample (Here Id is duplicate key):
[
{
"First Name": "ABC",
"Last Name": "XYZ",
"Gender": "MALE",
"Id": "123",
"moreDetails": {
"items": [
{
"Id": "123",
"City": "BLR",
"State": "KA"
}
]
}
}
]
Above json can be repeated like this also with any number:
[
{
"First Name": "ABC",
"Last Name": "XYZ",
"Gender": "MALE",
"Id": "123",
"moreDetails": {
"items": [
{
"Id": "123",
"City": "BLR",
"State": "KA"
}
]
}
},
{
"First Name": "Test",
"Last Name": "Me",
"Gender": "FEMALE",
"Id": "12345",
"moreDetails": {
"items": [
{
"Id": "12345",
"City": "KAN",
"State": "UP"
}
]
}
}
]
Output trying to achieve is by removed duplicate key which is Id:
[
{
"First Name": "ABC",
"Last Name": "XYZ",
"Gender": "MALE",
"Id": "123",
"City": "BLR",
"State": "KA"
},
{
"First Name": "Test",
"Last Name": "Me",
"Gender": "FEMALE",
"Id": "12345",
"City": "KAN",
"State": "UP"
}
]