# Set response value as Variable in Test

**URL:** <https://community.postman.com/t/set-response-value-as-variable-in-test/46213>\
**Category:** Help Hub\
**Tags:** tests, variables, collections\
**Created:** [April 11, 2023, 4:58pm UTC](https://community.postman.com/t/set-response-value-as-variable-in-test/46213 "2023-04-11T16:58:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 11, 2023, 5:25pm UTC](https://community.postman.com/t/set-response-value-as-variable-in-test/46213/2 "2023-04-11T17:25:23Z")

</div>

You’re using `pm.response.text()` here which isn’t required for a JSON response, as you can use `.json()` to get the data in a format that’s easily parsable.

This is what you would need to get the _first_ object’s `id` value:

```javascript
let response = pm.response.json();
pm.environment.set('folderID', response.data[0].id);

```

Ensure that you have an `environment` file created and selected or it will not capture the variable.

* * *

I wrote this a while ago about getting different values from a JSON response, it may help you here:

> [@Sharing tips and tricks with others in the Postman community](https://community.postman.com/t/sharing-tips-and-tricks-with-others-in-the-postman-community/5123/5):
>
> Extracting values from a JSON response I notice lots of questions from the community which all have a similar flavour - Users are having trouble extracting data from a JSON response body when the value is within an array. These are normally JavaScript related questions, more than specific Postman questions but I want to use this thread to offer more support around this problem. For these examples I’ll be using the [https://randomuser.me](https://randomuser.me) API, this returns lots of random user data, in a JSON form…

---

_[View the full topic](https://community.postman.com/t/set-response-value-as-variable-in-test/46213)._
