Hi,
I made a request that in a response gets a JSON that is a structure of an organization (arrays and data). My goal is to go through it to find a positon with specific name and check if it has a person assigned to it.
If I find the first position that name is correct (“name”: “Test”) and there is no person assigned (“personData”: null) then I wish to get the position id and save it as vairable, so I could use it in other requests.
It is very complicated for me, as I still lack the knowledge and experience in JS and Postman.
In the example below the position id that I look for would be in the last part of the JSNON (“id”: 12)
But this isn’t usually a case, it may be nested deeper or not and not always at the end.
{
"correctExecution": null,
"structure": {
"data": {
"id": -1,
"version": null,
"name": "Company",
"type": "COMP",
"exactMatch": false,
"assignedToPerson": false,
"personData": null
},
"children": [
{
"data": {
"id": 0,
"version": null,
"name": "Organization 1",
"type": "ORG",
"exactMatch": false,
"assignedToPerson": false,
"personData": null
},
"children": [
{
"data": {
"id": 1,
"version": 0,
"name": "Organization 2",
"type": "ORG",
"exactMatch": false,
"assignedToPerson": false,
"personData": null
},
"children": [
{
"data": {
"id": 2,
"version": 0,
"name": "Inspector 1",
"type": "POSITION",
"exactMatch": false,
"assignedToPerson": true,
"personData": {
"name": "John"
}
},
"children": null
},
{
"data": {
"id": 9,
"version": 0,
"name": "Inspector 2",
"type": "POSITION",
"exactMatch": false,
"assignedToPerson": true,
"personData": {
"name": "Will"
}
},
"children": null
}
]
},
{
"data": {
"id": 3,
"version": 0,
"name": "Organization 3",
"type": "ORG",
"exactMatch": false,
"assignedToPerson": false,
"personData": null
},
"children": [
{
"data": {
"id": 4,
"version": 0,
"name": "Inspector 4",
"type": "POSITION",
"exactMatch": false,
"assignedToPerson": true,
"personData": {
"name": "Anna"
}
},
"children": null
}
]
},
{
"data": {
"id": 10,
"version": 0,
"name": "Organization 4",
"type": "ORG",
"exactMatch": false,
"assignedToPerson": false,
"personData": null
},
"children": [
{
"data": {
"id": 11,
"version": 0,
"name": "Staff 1",
"type": "POSITION",
"exactMatch": false,
"assignedToPerson": true,
"personData": {
"name": "George"
}
},
"children": null
},
{
"data": {
"id": 12,
"version": 0,
"name": "Test",
"type": "POSITION",
"exactMatch": false,
"assignedToPerson": true,
"personData": null
},
"children": null
}
]
}
]
}
]
}
}
I’ve tried to combine a few solutions that I found here, with different functions. I tried to find the elements with lodash _.find _.filter. But I failed. I could find just a name or check if there is a personData.
Any help would be appreciated.