# Converting saved global variable to string in test script

**URL:** <https://community.postman.com/t/converting-saved-global-variable-to-string-in-test-script/41403>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [November 23, 2022, 12:00pm UTC](https://community.postman.com/t/converting-saved-global-variable-to-string-in-test-script/41403 "2022-11-23T12:00:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dine4fit](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@dine4fit](https://community.postman.com/u/dine4fit)\
**Post date:** [November 23, 2022, 12:00pm UTC](https://community.postman.com/t/converting-saved-global-variable-to-string-in-test-script/41403/1 "2022-11-23T12:00:03Z")

</div>

Hello, I want to assert dynamic user hash number in respond body in login api request. I created global variable of the dynamic user hash number and I have problem with assertion. I think it is because in console the number is a string and my global variable is not.

My question is, is it possible to convert a saved global variable to string to successfully assert with  
body respond?

 ![Screenshot_1](https://us1.discourse-cdn.com/getpostman/original/3X/c/5/c5473c98e4bac0b71fc9c031eb0946f7bc790ca5.png)  
 ![Screenshot_2](https://us1.discourse-cdn.com/getpostman/original/3X/e/e/ee8fb2f946047b66ff23876bfecd5a5510df8fb7.png)  
 ![Screenshot_3](https://us1.discourse-cdn.com/getpostman/original/3X/8/3/831ab63364f0a86344e22bf5726305835e24f57b.png)

---

<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:** [November 24, 2022, 12:50pm UTC](https://community.postman.com/t/converting-saved-global-variable-to-string-in-test-script/41403/2 "2022-11-24T12:50:11Z")

</div>

First thing is to work out what the variable actually is.

```auto
console.log(typeof("{{userHash}}"));

```

Once you know what it is, Postman is using JavaScript under the hood, so you just search on how to convert it to a string. Probably using toString().

However, I don’t really get your test. jsonObject is coming from the responseBody.  
You then set a global variable using the info from jsonObject.

You then assert on the two. I don’t really get this test, as it will always be true.  
How will you make the test fail, as you should do for all tests?
