I’m trying to flatten and merge a set of mixed objects\arrays but failed (
Sample:
{
"main": "xxx",
"phone_numbers": [
"+1234567890",
"+0987654321"
],
"branch": [{
"company": {
"name": "c_name1",
"head": "M.J.",
"location": {
"address": "address1",
"phone": "phone1"
},
"url": "name1.com"
},
"title": {
"name": "c_name1",
"role": "marketing",
"respons": [
"marketing",
"business administration"
]
},
"prev_location": [
"loc_name1",
"loc_name2"
],
"summary": "summary1"
},
{
"company": {
"name": "c_name2",
"head": "J.S.",
"location": {
"address": "address2",
"phone": "phone1"
},
"url": "name2.com"
},
"title": {
"name": "c_name2",
"role": "HR",
"respons": [
"planning",
"supervising the employment"
]
},
"location_names": [
"loc_name3",
"loc_name4"
],
"summary": "summary2"
}
]
}
Desired output:
{
"main": "xxx",
"phone_numbers": "+1234567890 , +0987654321",
"branch0-company": "name: c_name1; head: M.J.; address: address1; phone: phone1; url: name1.com",
"branch0-title": "name: c_name1; role: marketing; respons: marketing,business administration".
"branch0-prev_location": "loc_name1; loc_name2".
"branch0-summary": "summary1"
"branch1-company": "name: c_name2; head: J.S.; address: address2; phone: phone2; url: name1.com",
"branch1-title": "name: c_name1; role: marketing; respons: planning, supervising the employment ".
"branch1-prev_location": "loc_name3", "loc_name4".
"branch1-summary": "summary2"
}
The only thing I managed to do is flattening root array - Mongo playground
Any help or advice will be appreciated, thanks a lot.