# Use environment variable to object property name in tests

**URL:** <https://community.postman.com/t/use-environment-variable-to-object-property-name-in-tests/39499>\
**Category:** Help Hub\
**Tags:** tests, variables, json\
**Created:** [September 27, 2022, 9:17am UTC](https://community.postman.com/t/use-environment-variable-to-object-property-name-in-tests/39499 "2022-09-27T09:17:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulKP](https://avatars.discourse-cdn.com/v4/letter/p/e495f1/32.png) [@PaulKP](https://community.postman.com/u/PaulKP)\
**Post date:** [September 27, 2022, 9:17am UTC](https://community.postman.com/t/use-environment-variable-to-object-property-name-in-tests/39499/1 "2022-09-27T09:17:29Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.

_My question_:  
How in postman test use environment variable to object property name?

_Details (like screenshots)_:  
I get a response from request like this:  
{  
“something”: {  
“81071”: “Test name 1”,  
“81072”: “Test name 2”  
}

How I can use environment variables to make a test of id’s i geted (81071, 81072)?

_How I found the problem_:  
I get an object from response of my request and can’t test it with an environment variables.

_I’ve already tried_:  
I make test like this but i have an error.

pm.test(‘Value check’, () =\> {  
const expectedObject = {  
“something”: {  
“pm.environment.get(‘id1’)”: “Test name 1”,  
“pm.environment.get(‘id2’)”: “Test name 2”  
}  
};

```
pm.expect(response).to.deep.include(expectedObject);

```

});

---

<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:** [September 27, 2022, 11:00am UTC](https://community.postman.com/t/use-environment-variable-to-object-property-name-in-tests/39499/2 "2022-09-27T11:00:34Z")

</div>

```auto
response = pm.response.json();

pm.collectionVariables.set("id1", "81071");
pm.collectionVariables.set("id2", "81072");

const expectedObject = {
    "args": {
        [pm.collectionVariables.get("id1")]: "Test name 1",
        [pm.collectionVariables.get("id2")]: "Test name 2"
    }
};

pm.test("Value check", () => {
    pm.expect(response).to.deep.include(expectedObject);
});

```

---

<div class="post-metadata">

**Author:** ![PaulKP](https://avatars.discourse-cdn.com/v4/letter/p/e495f1/32.png) [@PaulKP](https://community.postman.com/u/PaulKP)\
**Post date:** [September 27, 2022, 12:27pm UTC](https://community.postman.com/t/use-environment-variable-to-object-property-name-in-tests/39499/3 "2022-09-27T12:27:16Z")

</div>

Thank you, for help! I didn’t know that I need to use ‘`[]`’ to environment variable if it in the property position. Have a nice day!
