I have a big objects with a lot of nested arrays and objects. What I am trying to do is adding a new key value pair to all nested objects (msn_data) if a matching id is found in another array of objects.
Here is the first object:
let firstData = {
"layout":[
{
"name": "Structure",
"hangars":[
[
{
"Structure":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 458741,
"structure": "S14/74",
"production": "in"
},
"tags": "TDS",
"visible": true
},
{
"msn_data": {
"id": 14587,
"structure": "S11/22",
"production": "in"
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
],
"buffer":[
[
{
"Midbuffer":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 489764,
"structure": "S10/04",
"production": "in"
},
"tags": "QL",
"visible": false
},
{
"msn_data": {
"id": 98745,
"structure": "S11/22",
"production": "in"
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
],
},
{
"name": "Equipment",
"hangars":[
[
{
"Equipment":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 3265456,
"structure": "S14/74",
"production": "in"
},
"tags": "TDS",
"visible": true
},
{
"msn_data": {
"id": 987521,
"structure": "S11/22",
"production": "in"
},
"tags": "TDS",
"visible": false
},
{
"msn_data": {
"id": 8524587,
"structure": "S11/22",
"production": "in",
},
"tags": "TDS",
"visible": false
},
{
"msn_data": {
"id": 36985471,
"structure": "S11/22",
"production": "in",
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
],
"buffer":[
[
{
"Midbuffer":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 489764,
"structure": "S10/04",
"production": "in"
},
"tags": "QL",
"visible": false
},
{
"msn_data": {
"id": 484630,
"structure": "S11/22",
"production": "in"
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
]
}
]
}
and here is the array of objects which I try to check for matching ids:
let secondData = [
{
"id": 458741,
"rowId": ":!!#9~d5f71e4a",
"matchData": true
},
{
"id": 489764,
"rowId": ":!!#9~d5f71e4a",
"matchData": true
},
{
"id": 7453215,
"rowId": ":!!#9~d5f71e4a",
"matchData": false
},
{
"id": 484630,
"rowId": ":!!#9~d5f71e4a",
"matchData": true
},
]
and this is what I am trying to achieve as soon as a matching id was found (add "owd": true if id matches, and "owd": false to all objects without matching id):
let firstData = {
"layout":[
{
"name": "Structure",
"hangars":[
[
{
"Structure":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 458741,
"structure": "S14/74",
"production": "in",
"owd": true
},
"tags": "TDS",
"visible": true
},
{
"msn_data": {
"id": 14587,
"structure": "S11/22",
"production": "in",
"owd": false
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
],
"buffer":[
[
{
"Midbuffer":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 489764,
"structure": "S10/04",
"production": "in",
"owd": true
},
"tags": "QL",
"visible": false
},
{
"msn_data": {
"id": 98745,
"structure": "S11/22",
"production": "in",
"owd": false
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
],
},
{
"name": "Equipment",
"hangars":[
[
{
"Equipment":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 3265456,
"structure": "S14/74",
"production": "in",
"owd": false
},
"tags": "TDS",
"visible": true
},
{
"msn_data": {
"id": 987521,
"structure": "S11/22",
"production": "in",
"owd": false
},
"tags": "TDS",
"visible": false
},
{
"msn_data": {
"id": 8524587,
"structure": "S11/22",
"production": "in",
"owd": false
},
"tags": "TDS",
"visible": false
},
{
"msn_data": {
"id": 36985471,
"structure": "S11/22",
"production": "in",
"owd": false
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
],
"buffer":[
[
{
"Midbuffer":{
"type": "dynamic",
"milestones": [],
"timeframe": "startDate",
"preFilter":{},
"stationData":{
"NONE":[
[
{
"msn_data": {
"id": 489764,
"structure": "S10/04",
"production": "in",
"owd": true
},
"tags": "QL",
"visible": false
},
{
"msn_data": {
"id": 484630,
"structure": "S11/22",
"production": "in",
"owd": true
},
"tags": "TDS",
"visible": false
},
]
]
}
}
}
]
]
}
]
}