# How to assert that the response body contains strings

**URL:** <https://community.postman.com/t/how-to-assert-that-the-response-body-contains-strings/14582>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [July 29, 2020, 12:10pm UTC](https://community.postman.com/t/how-to-assert-that-the-response-body-contains-strings/14582 "2020-07-29T12:10:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvixqa](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@silvixqa](https://community.postman.com/u/silvixqa)\
**Post date:** [July 29, 2020, 12:10pm UTC](https://community.postman.com/t/how-to-assert-that-the-response-body-contains-strings/14582/1 "2020-07-29T12:10:24Z")

</div>

Hi,

New to Postman and I would appreciate a little help.

I have the following response body and I would like to assert that “token\_data” contains the access\_token and refresh\_token that both have strings.  
{  
“token\_data”:{  
“access\_token”: “string”,  
“refresh\_token”: “string”  
}  
}

Help? 🙂

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [August 31, 2020, 9:25am UTC](https://community.postman.com/t/how-to-assert-that-the-response-body-contains-strings/14582/2 "2020-08-31T09:25:47Z")

</div>

Hello,

Yes it is possible.

You need to use type of.

Snippet below:

pm.test("Data Type is correct for access\_token " , function(){  
pm.expect(typeof(resp.token\_data[0].access\_token) === “string”).to.be.true;  
});

pm.test("Data Type is correct for refresh\_token " , function(){  
pm.expect(typeof(resp.token\_data[0].refresh\_token) === “string”).to.be.true;  
});

---

<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:** [August 31, 2020, 11:41am UTC](https://community.postman.com/t/how-to-assert-that-the-response-body-contains-strings/14582/3 "2020-08-31T11:41:59Z")

</div>

Another way to write the tests in addition to how @bpricilla demonstrated would be below:

```auto
pm.test('Access token is a string', function(){
  const jsonData = pm.response.json();
  pm.expect(jsonData.token_data).to.have.property('access_token').and.to.be.a('string');
}

```

What’s nice about this method is that if you also want to test the value, you could change it to something like this:

```auto
pm.test('Access token has correct string', function(){
  const jsonData = pm.response.json();
  const expectedValue = 'my_access_token_expected_value';
  pm.expect(jsonData.token_data).to.have.property('access_token', expectedValue);
}

```
