# Extract specific value from JSON Response

**URL:** <https://community.postman.com/t/extract-specific-value-from-json-response/21122>\
**Category:** Help Hub\
**Created:** [March 8, 2021, 12:15pm UTC](https://community.postman.com/t/extract-specific-value-from-json-response/21122 "2021-03-08T12:15:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [March 8, 2021, 12:15pm UTC](https://community.postman.com/t/extract-specific-value-from-json-response/21122/1 "2021-03-08T12:15:36Z")

</div>

Hi Team,

I am running one Rest API which gives response as below:

```auto
[
    {
        "message": "You can use the OTP 79744 to login to your account. Use it within 3 minutes before it expires. Please do not share this OTP with anyone."
    }
]

```

So how to extract OTP values in one variable, specifically via regular expression?

However, via JS string function, I can achieve it but wanted to do it via regular expression

```auto
let str = `You can use the OTP 79744 to login to your account. Use it within 3 minutes before it expires. Please do not share this OTP with anyone.`;
let substring = str.substring(20,26);
console.log(substring);

```

I can further utilize the substring variable which contains the OTP values.

Thanks

---

<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:** [March 8, 2021, 12:43pm UTC](https://community.postman.com/t/extract-specific-value-from-json-response/21122/2 "2021-03-08T12:43:55Z")

</div>

A very non-robust and hacky way of getting it could be as simple as:

```auto
console.log(pm.response.json()[0].message.match(/\d+/)[0])

```

As it’s not doing a global match, it will get the first number in the `message` property and then you can select the first item in the `match` array.

I wouldn’t recommend using that any further that just trying things out locally 😬

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [March 8, 2021, 5:00pm UTC](https://community.postman.com/t/extract-specific-value-from-json-response/21122/3 "2021-03-08T17:00:01Z")

</div>

Thanks @danny-dainton for the prompt response.
