Traverse response path when it contains a guid

Hi, I have a response returned in the format below, What I am trying to do is get the value of the “id”, inside of the first object in the newOrUpdateEvents list.

The challenge I am having is the guids that refer to the id can change depending on the state of data. Changing data is changing guids

I need to know how to traverse the tree with a changing path name

so data.events.newOrUpdatedEvents will always be consistent, then the guid will change and then I want to retrieve the first id

Thanks in advance

{
    "data": {
        "events": {
            "isLocked": false,
            "newOrUpdatedEvents": {
                "10da21f3-6172-4916-955a-296b4ad98896": {
                    "id": "10da21f3-6172-4916-955a-296b4ad98896"                   
                },
                "08152a91-bae2-4939-91f4-e1e39bd2460b": {
                    "id": "08152a91-bae2-4939-91f4-e1e39bd2460b"                 
				}            
			},
	    "pending": [],
            "validationResults": {},
            "referenceEvents: {}
		}
	}
}	

Hi @cryosat-operator-620. Welcome to the Postman community.

This question looks like it is more JavaScript related than it is Postman related.

Javascript has multiple methods that allow you to traverse through objects.

For in loops - MDN Docs

Object.entries - MDN Docs.

Object.values - MDN Docs.

By using object values.

console.log(Object.values(response.data.events.newOrUpdatedEvents)[0].id); 

Hey thanks for this, thats amazing.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.