# Extract request variable

**URL:** <https://community.postman.com/t/extract-request-variable/59998>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [April 16, 2024, 9:24am UTC](https://community.postman.com/t/extract-request-variable/59998 "2024-04-16T09:24:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayal1postman](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@kayal1postman](https://community.postman.com/u/kayal1postman)\
**Post date:** [April 16, 2024, 9:24am UTC](https://community.postman.com/t/extract-request-variable/59998/1 "2024-04-16T09:24:30Z")

</div>

Hi ,  
I need to get the value from the request sent and verify it against the response. So, I need to write the test in that I need to extract the value from the body of the request and compare it with the response variable. The body of the request contains some environment variables as well but this particular field that I need to extract the value is not an environment variable. How do I do that? Kindly assist. your help is much appreciated.

---

<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:** [April 16, 2024, 9:29am UTC](https://community.postman.com/t/extract-request-variable/59998/2 "2024-04-16T09:29:00Z")

</div>

Hey @kayal1postman 👋,

In order for anyone to help here, you would need to share examples of the request body, what actual value you need to get and what part of the response are you verifying it against.

You’re trying to explain it, without actually showing what it is you’re looking at 🙏

---

<div class="post-metadata">

**Author:** ![kayal1postman](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@kayal1postman](https://community.postman.com/u/kayal1postman)\
**Post date:** [April 16, 2024, 9:36am UTC](https://community.postman.com/t/extract-request-variable/59998/3 "2024-04-16T09:36:01Z")

</div>

Hi,  
Below is the request eg:

```auto
{
    "DummyObject": {
        "DummyObject1": {
            "Name": "Mr Doe"
        }
    }
}

```

Response eg:

```auto
{
    "Rip": {},
    "ID": "123VBXXXXXXXXXX",
    "DummyObject": {
        "DummyObject1": {
            "Name": "Mr Doe"
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [April 16, 2024, 11:12am UTC](https://community.postman.com/t/extract-request-variable/59998/4 "2024-04-16T11:12:58Z")

</div>

Which field in the request do you want to target?

You can access the body of a request using the following.

```auto
const body = JSON.parse(pm.request.body.raw);

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [May 16, 2024, 11:13am UTC](https://community.postman.com/t/extract-request-variable/59998/5 "2024-05-16T11:13:15Z")

</div>

Closed on May 16, 2024, 11:13am UTC

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