I want to merge two multi-level object to form a single object with no loss of data. till the level data is same no extra fields should be added, at level where fields are different new object should get inserted in the array.
we have to group json object of similar fields in one complete json. multilevel object needs to be merged together to get one aggragated result. my sample objects are as -
let one={
"name": "Hindi",
"country": "USA",
"region": "EAST COAST",
"enttity": "ENTITY-2",
"operation": [
{
"p_name": "RECONSTRUCTION",
"code": "jhhkj-132",
"class": "medical",
"products": [
{
"main": "electronic",
"area": [
{
"subarea": "electrical",
"use": 0,
"max_use": 0,
"mode_use": "10",
"median": "12",
"things": [
{
"id": "1000514",
"number": "1588TB-1",
"description": "DESCRIPTION1",
"manufacturer": "LG",
"tag": "NOT AVAILABLE",
}
]
}
]
}
]
}
]
};
let two={
"name": "Hindi",
"country": "USA",
"region": "EAST COAST",
"enttity": "ENTITY-2",
"operation": [
{
"p_name": "RECONSTRUCTION",
"code": "jhhkj-132",
"class": "medical",
"products": [
{
"main": "electronic",
"area": [
{
"subarea": "mechanical",
"use": 0,
"max_use": 0,
"mode_use": "10",
"median": "12",
"things": [
{
"id": "1000523314",
"number": "1588T3B-1",
"description": "DES32CRIPTION1",
"manufacturer": "LG",
"tag": "NOT AVAILABLE",
}
]
},
{
"subarea": "electrical",
"use": 0,
"max_use": 0,
"mode_use": "10",
"median": "12",
"things": [
{
"id": "1000514",
"number": "1588TB-1",
"description": "DESCRIPTION1",
"manufacturer": "LG",
"tag": "NOT AVAILABLE",
}
]
}
]
}
]
}
]
};
output json should be something like this->
let outpus={
"name": "Hindi",
"country": "USA",
"region": "EAST COAST",
"enttity": "ENTITY-2",
"operation": [
{
"p_name": "RECONSTRUCTION",
"code": "jhhkj-132",
"class": "medical",
"products": [
{
"main": "electronic",
"area": [
{
"subarea": "mechanical",
"use": 0,
"max_use": 0,
"mode_use": "10",
"median": "12",
"things": [
{
"id": "1000523314",
"number": "1588T3B-1",
"description": "DES32CRIPTION1",
"manufacturer": "LG",
"tag": "NOT AVAILABLE",
}
]
},
{
"subarea": "electrical",
"use": 0,
"max_use": 0,
"mode_use": "10",
"median": "12",
"things": [
{
"id": "1000514",
"number": "1588TB-1",
"description": "DESCRIPTION1",
"manufacturer": "LG",
"tag": "NOT AVAILABLE",
}
]
}
]
}
]
}
]
};