After searching for solutions on how to filter nested arrays, I found multiple sources that mentioned dealing with arrays within other arrays. However, in my particular case, the challenge lies in handling an array nested within an object.
The array in question is structured as follows:
{
"msg": "OK",
"blueprint": {
"result": "OK",
"blueprint": {
"id": "a2e63ee01401aaeca78be023dfbb8c59",
"product": {
"productName": "Test Product",
"productId": "AS_12-01",
"description": "Test Descr.",
"childProducts": [
{
"childId": "T1",
"parent": "8c59"
},
{
"childId": "T5",
"parent": "8c7e"
}
],
"components": [
{
"compId": "C2", #
"leadTime": 21, # remove
"available": false #
},
{
"compId": "C5",
"leadTime": 3,
"available": true
},
{
"compId": "C6", #
"leadTime": 12, # remove
"available": false #
},
{
"compId": "C8",
"leadTime": 5,
"available": true
},
]
},
"owner": "dummy",
"name": "du_test"
}
}
}
My goal is to filter the nested array in such a way that the resulting object retains its structure but excludes any unavailable objects.
{
"msg": "OK",
"blueprint": {
"result": "OK",
"blueprint": {
"id": "a2e63ee01401aaeca78be023dfbb8c59",
"product": {
"productName": "Test Product",
"productId": "AS_12-01",
"description": "Test Descr.",
"childProducts": [
{
"childId": "T1",
"parent": "8c59"
},
{
"childId": "T5",
"parent": "8c7e"
}
],
"components": [
{
"compId": "C5",
"leadTime": 3,
"available": true
},
{
"compId": "C8",
"leadTime": 5,
"available": true
},
]
},
"owner": "dummy",
"name": "du_test"
}
}
}
In essence, the desired outcome is to retain the original structure while removing the unavailable objects from the nested array.
Any suggestions on how to accomplish this task?