# Get properties from JSON object by name

**URL:** <https://community.postman.com/t/get-properties-from-json-object-by-name/7684>\
**Category:** Help Hub\
**Tags:** json\
**Created:** [September 10, 2019, 12:01pm UTC](https://community.postman.com/t/get-properties-from-json-object-by-name/7684 "2019-09-10T12:01:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![e.mikhailov](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@e.mikhailov](https://community.postman.com/u/e.mikhailov)\
**Post date:** [September 10, 2019, 12:01pm UTC](https://community.postman.com/t/get-properties-from-json-object-by-name/7684/1 "2019-09-10T12:01:01Z")

</div>

I wrote this script to check equality of custom attributes of object

> pm.test(“…”, function () {  
> var jsonData = pm.response.json(),  
> propertiesToCheck = [‘availableToClient’, ‘contextId’, ‘defaultValue’, ‘description’,  
> ‘label’, ‘sectionId’, ‘valueType’, ‘values’],  
> body = JSON.parse(pm.environment.get(“body”));
> 
> ```
> propertiesToCheck.forEach((p) => 
> pm.expect(jsonData).to.have.deep.property(p, body.p));
> 
> ```
> 
> });

Variable body contains body of my request, f. e.

> var body = JSON.stringify(  
> {  
> “availableToClient”: true,  
> “contextId”: 1,  
> “defaultValue”: 2,  
> “description”: “some desc”,  
> “label”: “some label”,  
> “sectionId”: 1,  
> “valueType”: “INTEGER”,  
> “values”: [1, 2, 3]  
> });
> 
> pm.environment.set(‘body’, body);

But it doesn’t work that way, because expression `body.p` means get attribute with the name “p”. If there is a way to read attribute with the name which is written at variable?

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [September 10, 2019, 12:58pm UTC](https://community.postman.com/t/get-properties-from-json-object-by-name/7684/2 "2019-09-10T12:58:16Z")

</div>

Instead of writing `body.p`, you have to write `body[p]`

---

<div class="post-metadata">

**Author:** ![e.mikhailov](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@e.mikhailov](https://community.postman.com/u/e.mikhailov)\
**Post date:** [September 10, 2019, 12:58pm UTC](https://community.postman.com/t/get-properties-from-json-object-by-name/7684/3 "2019-09-10T12:58:39Z")

</div>

Thanks, just got it at the moment!
