# Parse global or collection variable

**URL:** <https://community.postman.com/t/parse-global-or-collection-variable/35744>\
**Category:** Help Hub\
**Tags:** variables, json\
**Created:** [May 29, 2022, 1:32am UTC](https://community.postman.com/t/parse-global-or-collection-variable/35744 "2022-05-29T01:32:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksully](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@ksully](https://community.postman.com/u/ksully)\
**Post date:** [May 29, 2022, 1:32am UTC](https://community.postman.com/t/parse-global-or-collection-variable/35744/1 "2022-05-29T01:32:41Z")

</div>

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.

```auto
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));

```

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [May 29, 2022, 7:21pm UTC](https://community.postman.com/t/parse-global-or-collection-variable/35744/2 "2022-05-29T19:21:01Z")

</div>

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;

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

```

As per the documentation found here:

> **[Postman JavaScript reference | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-environment-variables-in-scripts)**
>
> Postman JavaScript reference: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

Hope this helps… ?

---

<div class="post-metadata">

**Author:** ![ksully](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@ksully](https://community.postman.com/u/ksully)\
**Post date:** [June 4, 2022, 11:16am UTC](https://community.postman.com/t/parse-global-or-collection-variable/35744/3 "2022-06-04T11:16:59Z")

</div>

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
