# Check if a field contains a certain value

**URL:** <https://community.postman.com/t/check-if-a-field-contains-a-certain-value/45828>\
**Category:** Help Hub\
**Tags:** tests, collections, scripts\
**Created:** [March 31, 2023, 1:26am UTC](https://community.postman.com/t/check-if-a-field-contains-a-certain-value/45828 "2023-03-31T01:26:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvio.aulik](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/silvio.aulik/32/15645_2.png) [@silvio.aulik](https://community.postman.com/u/silvio.aulik)\
**Post date:** [March 31, 2023, 1:26am UTC](https://community.postman.com/t/check-if-a-field-contains-a-certain-value/45828/1 "2023-03-31T01:26:05Z")

</div>

How can I test if key `gender` is either **1** or **2** , please?

```auto
"naturalPerson": {
        "fullName": "Teste with Luis",
        "nickName": "Pacheco",
        "gender": 2,
        "pronoun": 2,

```

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [March 31, 2023, 7:50am UTC](https://community.postman.com/t/check-if-a-field-contains-a-certain-value/45828/2 "2023-03-31T07:50:20Z")

</div>

Hi @silvio.aulik

Assuming your response looks like this:

```auto
{
    "naturalPerson": {
        "fullName": "Teste with Luis",
        "nickName": "Pacheco",
        "gender": 2,
        "pronoun": 2
    }
}

```

Then to check the ‘value is 1 or 2’ you could use the following

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

pm.test("Check value is either 1 or 2", function () {
    pm.expect(response.naturalPerson.gender).to.be.oneOf([1, 2]);
});

```

---

<div class="post-metadata">

**Author:** ![silvio.aulik](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/silvio.aulik/32/15645_2.png) [@silvio.aulik](https://community.postman.com/u/silvio.aulik)\
**Post date:** [March 31, 2023, 11:30am UTC](https://community.postman.com/t/check-if-a-field-contains-a-certain-value/45828/3 "2023-03-31T11:30:29Z")

</div>

Your are the best!!.. Thank you x 1000…  
Be happy

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [January 26, 2024, 4:54pm UTC](https://community.postman.com/t/check-if-a-field-contains-a-certain-value/45828/4 "2024-01-26T16:54:36Z")

</div>

Closed on January 26, 2024, 4:54pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
