# Parse Json to get value in collectionVariables

**URL:** <https://community.postman.com/t/parse-json-to-get-value-in-collectionvariables/15007>\
**Category:** Help Hub\
**Tags:** variables, json\
**Created:** [August 13, 2020, 1:33pm UTC](https://community.postman.com/t/parse-json-to-get-value-in-collectionvariables/15007 "2020-08-13T13:33:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phyxius](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Phyxius](https://community.postman.com/u/Phyxius)\
**Post date:** [August 13, 2020, 1:33pm UTC](https://community.postman.com/t/parse-json-to-get-value-in-collectionvariables/15007/1 "2020-08-13T13:33:44Z")

</div>

Hi there,

I am trying to understand how to parse json with Postman.  
My goal is to retrieve the value of WorkstationId and store it into collectionVariables.  
Could some one point me in the right direction?

**This is how far I got but it failed:**

```auto
pm.collectionVariables.set("GETWorkstationIdStore", pm.response.json().value[0].Workstations.WorkstationId);

let GETWorkstationId = pm.variables.get("GETWorkstationIdStore");
console.log("WorkstationId from GET = " + GETWorkstationId)

```

**My JSON file**

```auto
  "@odata.context": "https://doesnotexist/MyApi/api/v1.0/$metadata#locations",
  "value": [
    {
      "LocationIdInternal": 1,
      "LocationId": "B9507A00-9057-4CCC-A66B-9AAAB1B6CA5B",
      "DisplayName": "DEFAULT_LOCATION",
      "IsActive": true,
      "Workstations": [
        {
          "WorkstationIdInternal": 3,
          "WorkstationId": "8E5B3291-E092-4091-8C9A-58B7C90E907C",
          "WorkstationName": "OVER77",
          "WorkstationType": "Default"
        }
      ]
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 13, 2020, 1:52pm UTC](https://community.postman.com/t/parse-json-to-get-value-in-collectionvariables/15007/2 "2020-08-13T13:52:17Z")

</div>

Hey @Phyxius

You should be able to do just this in the Tests for that request:

```auto
let GETWorkstationId = pm.response.json().value[0].Workstations[0].WorkstationId

console.log("WorkstationId from GET = " + GETWorkstationId)

pm.collectionVariables.set("GETWorkstationIdStore", GETWorkstationId);

```

---

<div class="post-metadata">

**Author:** ![Phyxius](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Phyxius](https://community.postman.com/u/Phyxius)\
**Post date:** [August 13, 2020, 1:59pm UTC](https://community.postman.com/t/parse-json-to-get-value-in-collectionvariables/15007/3 "2020-08-13T13:59:46Z")

</div>

Perfect, thank you very much.  
Much appreciated

Do you know of any document where I can readup on how to build parse JSON like you did:  
_.value[0].Workstations[0].WorkstationId_

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 13, 2020, 3:42pm UTC](https://community.postman.com/t/parse-json-to-get-value-in-collectionvariables/15007/4 "2020-08-13T15:42:43Z")

</div>

No worries. Happy to help.

Not sure what you mean? Do you mean in terms of looping through those arrays rather than hard coding the index numbers?

---

<div class="post-metadata">

**Author:** ![Phyxius](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Phyxius](https://community.postman.com/u/Phyxius)\
**Post date:** [August 14, 2020, 8:54am UTC](https://community.postman.com/t/parse-json-to-get-value-in-collectionvariables/15007/5 "2020-08-14T08:54:43Z")

</div>

Both actually.  
I am starting to learn.  
So I can image that there is a tutorial of some sort that will explain to me how to build parameter for pm.responds.json.

for instance my line was  
pm.response.json().value[0].Workstations.WorkstationId  
btu it shoudl have been  
pm.response.json().value[0].Workstations[0].WorkstationId

difference in the line is apparent  
I would like to know why and when to apply those parameters.

Also looping through arrays sounds something I can use.  
Would like to know more. 🙂
