Parse global or collection variable

To verify a request, we defined a json structure in a variable (global or collection), and need to parse it to check certain data fields against the request reponse.
The only way we’ve been able to do this is with the deprecated language below.
Can anyone point us to a more current way to do this?
This example shows the value (variable) being defined, then parsed.

const obj = {
            "eventContext": {
                "eventName": "commentCreated",
                "eventId": "53973f1d-ec2a-457a-af69-b29bfb016f45",
                "eventDatetime": "2022-05-16T15:45:01.4729967-04:00"
            },
            "commentId": "140c04ed-afe0-4d5f-b283-e574cd63fc47",
            "entityType": "story",
            "entityId": "c0123e45",
            "commentUserId": "01010101010101"
        };
postman.setEnvironmentVariable("obj", JSON.stringify(obj));
const obj2 = {
            "eventContext": {
                "eventName": "moderationCreated",
                "eventId": "7f608f6d-fe04-4e8c-85d4-dbd6371bd4df",
                "eventDatetime": "2022-05-16T15:45:03.3779789-04:00"
            },
            "commentId": "c7238f62-534f-41fa-bd95-4673cec6b07b",
            "entityType": "moderate",
            "entityId": "c1234f56",
            "commentUserId": "01010101010101"
        };
postman.setEnvironmentVariable("obj2", JSON.stringify(obj2));

Hi @ksully

Im not sure I follow exactly what you are trying to achieve. But I do know that the “postman” API was/is being replaced by the “pm” API.

As such the set variable command would be;

pm.environment.set(variableName:String, variableValue:*):function

As per the documentation found here:

Hope this helps… ?

Setting a variable holding a POST request body, so that it can be used in checking the return data in a subsequent Get request. Helps in maintenance by having one place where that data is defined.

So need to read that variable (json) , parse it and reference fields to verify the data.
We have the deprecated code I showed above, but we can’t find the equivalent in ‘pm’ code