Postman Json Response capture specific nested fields info and save as a variable used it in next step

Hi Team,

I am having issue capturing specific data from response , saving as variable and using that variable in the next step.

Here’s an outline with best practices for making your inquiry.

My question:

Details (like screenshots):
Here is my json response

{
    "data": {
        "serviceProfileList": {
            "pageInfo": {
                "total": 7
            },
            "edges": [
                {
                    "node": {
                        "id": "BlwDBAQKnZ_jmWhmicdW8otSMJE",
                        "name": "IoT Connectivity 5G - Data, SMS & Voice New 14",
                        "simRefs": {
                            "edges": [
                                {
                                    "node": {
                                        "imsi": 228022000000345,
                                        "iccid": "89410210694400003456"
                                    }
                                }
                            ]
                        }
                    },
                    "cursor": "Qmx3REJBUUtuWl9qbVdobWljZFc4b3RTTUpFIyNwb3MtMQ",
                    "cursorPosition": 1
                },
                {
                    "node": {
                        "id": "BlwDBBP_iY-sPtNh_I8vrMdS7aA",
                        "name": "IoT Connectivity - Data Only T3",
                        "simRefs": {
                            "edges": [
                                {
                                    "node": {
                                        "imsi": 228022000000347,
                                        "iccid": "89410210694400003472"
                                    }
                                }
                            ]
                        }
                    },
                    "cursor": "Qmx3REJCUF9pWS1zUHROaF9JOHZyTWRTN2FBIyNwb3MtMg",
                    "cursorPosition": 2
                },
                {
                    "node": {
                        "id": "BlwDBFK7i6nYITnDSzPODD4Ji50",
                        "name": "IoT Connectivity - Data, SMS & Voice Roaming",
                        "simRefs": {
                            "edges": []
                        }
                    },
                    "cursor": "Qmx3REJGSzdpNm5ZSVRuRFN6UE9ERDRKaTUwIyNwb3MtMw",
                    "cursorPosition": 3
                },
                {
                    "node": {
                        "id": "BlwDBG2qsvkcc3PxYPBrr3iXjA4",
                        "name": "IoT Connectivity - Data, SMS & Voice Roam RT",
                        "simRefs": {
                            "edges": [
                                {
                                    "node": {
                                        "imsi": 228022000000340,
                                        "iccid": "89410210694400003407"
                                    }
                                }
                            ]
                        }
                    },
                    "cursor": "Qmx3REJHMnFzdmtjYzNQeFlQQnJyM2lYakE0IyNwb3MtNA",
                    "cursorPosition": 4
                },
                {
                    "node": {
                        "id": "BlwDBKiFSOAZDoVhQ19520--9mY",
                        "name": "IoT Connectivity 5G - Data, SMS & Voice New",
                        "simRefs": {
                            "edges": [
                                {
                                    "node": {
                                        "imsi": 228022000000348,
                                        "iccid": "89410210694400003480"
                                    }
                                }
                            ]
                        }
                    },
                    "cursor": "Qmx3REJLaUZTT0FaRG9WaFExOTUyMC0tOW1ZIyNwb3MtNQ",
                    "cursorPosition": 5
                },
                {
                    "node": {
                        "id": "BlwDBLWWDBoWGHUvSWAP64nhs8s",
                        "name": "IoT Connectivity 5G - Data, SMS & Voice",
                        "simRefs": {
                            "edges": []
                        }
                    },
                    "cursor": "Qmx3REJMV1dEQm9XR0hVdlNXQVA2NG5oczhzIyNwb3MtNg",
                    "cursorPosition": 6
                },
                {
                    "node": {
                        "id": "BlwDBOc5O0DmsprK7cayVaUgJO4",
                        "name": "IoT Connectivity - Data, SMS & Voice",
                        "simRefs": {
                            "edges": [
                                {
                                    "node": {
                                        "imsi": 228022000000346,
                                        "iccid": "89410210694400003464"
                                    }
                                }
                            ]
                        }
                    },
                    "cursor": "Qmx3REJPYzVPMERtc3BySzdjYXlWYVVnSk80IyNwb3MtNw",
                    "cursorPosition": 7
                }
            ]
        }
    }
}

From this graphql api response want to get all the node ids and the related imsi fields info.

                                    "imsi": 228022000000345,
                                 "id": "BlwDBAQKnZ_jmWhmicdW8otSMJE"

Can someone please help me in getting this nested json array field values

How I found the problem:

I’ve already tried:

I managed to get all the ids but not the imsi field values

size.each(function(edges){

console.log(edges.node.id)

})

Hi @mahesh9ms ,

It looks like the trouble that you are having is with the fact that there can be one to many edges within the simRefs. You need to create a nested forEach to obtain those values.

I have created this using you json as a CollectionVariable that I obtained the data in the Test of a Request:

let test_data = JSON.parse(pm.collectionVariables.get("test_data"));

test_data.data.serviceProfileList.edges.forEach(function(edges){
    console.log("ID: " + edges.node.id);
    edges.node.simRefs.edges.forEach(function(sub_edges){
        console.log("IMSI: " + sub_edges.node.imsi);    
    });
});

Let me know if you need any additional information for this.

Hope this helps!