# Get a specific value from a response body

**URL:** <https://community.postman.com/t/get-a-specific-value-from-a-response-body/35967>\
**Category:** Help Hub\
**Created:** [June 6, 2022, 8:18am UTC](https://community.postman.com/t/get-a-specific-value-from-a-response-body/35967 "2022-06-06T08:18:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaga85](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@shaga85](https://community.postman.com/u/shaga85)\
**Post date:** [June 6, 2022, 8:18am UTC](https://community.postman.com/t/get-a-specific-value-from-a-response-body/35967/1 "2022-06-06T08:18:11Z")

</div>

Hi guys, i need some help:

How can i get a specific value from a link that i got in a response and set it as a variable? The response is:

```auto
{
    "value": "otpauth://totp/BTTExchange:teste123@mailinator.com?algorithm=SHA1&digits=6&issuer=WITExchange&period=30&secret=44RN6GN38TDRXZ5HXDCDA7TTWCB3YWJG"
}

```

and all i want is to set the value of secret=, being 44RN6GN38TDRXZ5HXDCDA7TTWCB3YWJG as a variable.

Im using:

```auto
var body = responseBody;
if(body!=null && body.length>0){
    var array = new RegExp("\"value\":\"(.*?)\"").exec(body);
    if(array!=null && array.length>0 && array[1]!=null){
        pm.globals.set("secret", ""+array[1]);
    }
}

```

but all i get is the whole “value”, and not only the secret=.

I know this must be something pretty basic, but im no developer nor do i know how to code.

Thanks in advance!

---

<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:** [June 6, 2022, 8:33am UTC](https://community.postman.com/t/get-a-specific-value-from-a-response-body/35967/2 "2022-06-06T08:33:27Z")

</div>

Hi @shaga85

Just change your regex a little bit;

```auto
var body = responseBody;
if(body!=null && body.length>0){
    var array = new RegExp("secret\=(.*?)\"").exec(body);
    if(array!=null && array.length>0 && array[1]!=null){
        //pm.globals.set("secret", ""+array[1]);
        console.log(array[1]);
    }
}

```

---

<div class="post-metadata">

**Author:** ![shaga85](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@shaga85](https://community.postman.com/u/shaga85)\
**Post date:** [June 6, 2022, 8:57am UTC](https://community.postman.com/t/get-a-specific-value-from-a-response-body/35967/3 "2022-06-06T08:57:04Z")

</div>

Nice, thanks a bunch! It worked 🙂
