# How to extract POST request field values in other GET tests

**URL:** <https://community.postman.com/t/how-to-extract-post-request-field-values-in-other-get-tests/17391>\
**Category:** Help Hub\
**Created:** [November 3, 2020, 9:57pm UTC](https://community.postman.com/t/how-to-extract-post-request-field-values-in-other-get-tests/17391 "2020-11-03T21:57:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mina\_jk](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Mina\_jk](https://community.postman.com/u/Mina_jk)\
**Post date:** [November 3, 2020, 9:57pm UTC](https://community.postman.com/t/how-to-extract-post-request-field-values-in-other-get-tests/17391/1 "2020-11-03T21:57:20Z")

</div>

I am trying to put the POST request (not Response) into a global variable like this :

let requestJson = pm.request.toJSON();  
pm.globals.set(“aRequestAsJson”, requestJson);

then there is another GET request which retrieves a set of data. I want to compare the field values from this GET response to the field values in the request(that I have in global variable above). somehow I am not able to read any value. the global variable value is just shown as object object

var x = pm.globals.get(“aRequestAsJson”)  
console.log(" aRequestAsJson in GET as JSON: " + x);  
console.log("abbreviatedDays from REquest : " + x.body.abbrDays);

Can I please get some help in reading the request values from global variable? plan is to then compare the values from global variable(request) with the GET response fields in

pm.expect(pm.response.json().getByAbbrDays).not.eql( x.AbbrDays);

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [November 4, 2020, 12:48pm UTC](https://community.postman.com/t/how-to-extract-post-request-field-values-in-other-get-tests/17391/2 "2020-11-04T12:48:05Z")

</div>

I’d modify your scripts slightly.

For saving the request to a global variable:

```auto
const requestJson = pm.request.toJSON();
pm.globals.set('aRequestAsJson', JSON.stringify(requestJson));

```

When loading it back in your test scripts, just make sure you parse it back into a json object:

```auto
const x = JSON.parse(pm.globals.get('aRequestAsJson'));

```

---

<div class="post-metadata">

**Author:** ![Mina\_jk](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Mina\_jk](https://community.postman.com/u/Mina_jk)\
**Post date:** [November 4, 2020, 2:49pm UTC](https://community.postman.com/t/how-to-extract-post-request-field-values-in-other-get-tests/17391/3 "2020-11-04T14:49:19Z")

</div>

Thank You Allen,

I tried this : const requestJson = pm.request.toJSON();  
pm.globals.set(‘aRequestAsJson’, JSON.stringify(requestJson));

and printed **console.log(" aRequestAsJson :**" + requestJson);  
it prints as " aRequestAsJson : **[object Object]**"

then in loading back scripts I printed aRequestAsJson to log :  
var x = JSON.parse(pm.globals.get(“aRequestAsJson”)); //Nov 04  
**console.log** (" aRequestAsJson in GET as JSON: " + x);

it printed as : " aRequestAsJson in GET as JSON: **[object Object]**"

then I printed the filed that I want to read as :  
console.log("abbrDays from Request : " + **x.body.abbrDays** );

and it printed as “abbrDays from Request : **undefined** ”

How do I read the field values?

---

<div class="post-metadata">

**Author:** ![yusuftaymann](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/yusuftaymann/32/6160_2.png) [@yusuftaymann](https://community.postman.com/u/yusuftaymann)\
**Post date:** [November 4, 2020, 8:31pm UTC](https://community.postman.com/t/how-to-extract-post-request-field-values-in-other-get-tests/17391/4 "2020-11-04T20:31:28Z")

</div>

Hi @Mina_jk ,

You need to parse the part that returns from the body and pull its content, you can use it as follows.

```
const requestJson = pm.request.toJSON();
pm.globals.set('aRequestAsJson', JSON.stringify(requestJson));
const x = JSON.parse(pm.globals.get('aRequestAsJson'));
console.log(x.body.raw);
console.log(JSON.parse(x.body.raw).name);

```

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/6/c6ed2fb22d5d80e218dba9e5a2d54a4029dee1a7.png)

---

<div class="post-metadata">

**Author:** ![Mina\_jk](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Mina\_jk](https://community.postman.com/u/Mina_jk)\
**Post date:** [November 6, 2020, 2:35am UTC](https://community.postman.com/t/how-to-extract-post-request-field-values-in-other-get-tests/17391/5 "2020-11-06T02:35:25Z")

</div>

Thank You Yusuf, That worked!  
Thanks a much!
