# Using OR Statement to Validate String In Multiple JSON Attributes?

**URL:** <https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [April 16, 2020, 9:23pm UTC](https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005 "2020-04-16T21:23:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKSG](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SKSG](https://community.postman.com/u/SKSG)\
**Post date:** [April 16, 2020, 9:23pm UTC](https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005/1 "2020-04-16T21:23:58Z")

</div>

I am trying to validate the results from a Search query. The objects within the JSON response include a Title and Description. For my basic test, I want to make sure that the search query is included in the title OR the description. To try and solve this, I used:  
`(pm.expect(title).to.include(search) || pm.expect(description).to.include(search))` and the test is passing, but I want to make sure its not a false positive. Any tips are appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [April 16, 2020, 9:40pm UTC](https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005/2 "2020-04-16T21:40:50Z")

</div>

@SKSG,

Because a failing assertion will throw an error, using `||` won’t work. You can try something like this:

```auto
const search = 'find me';
const title = 'hi there';
const description = 'going to find me soon';

pm.test('search is included in title or description', () => {
    pm.expect(search).satisfies((s) => {
        return title.includes(search) ||
            description.includes(search);
    });
});

```

Best,

Kevin

---

<div class="post-metadata">

**Author:** ![SKSG](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SKSG](https://community.postman.com/u/SKSG)\
**Post date:** [April 17, 2020, 2:57pm UTC](https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005/3 "2020-04-17T14:57:54Z")

</div>

I’ll try that, thanks! I just realized, couldn’t I also use an If -\> Else If statement as well? While the order of the conditions being met doesn’t really matter, it will potentially look through both attributes anyway to find the search term.

---

<div class="post-metadata">

**Author:** ![SKSG](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SKSG](https://community.postman.com/u/SKSG)\
**Post date:** [April 17, 2020, 3:06pm UTC](https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005/4 "2020-04-17T15:06:10Z")

</div>

P.S. - What is that .satisfies((s) function? I’m not finding any documentation on it, but I’m assuming it expects a ‘true’ value to be returned from any of the assertions being tested. What else can I use it for?

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [April 17, 2020, 5:19pm UTC](https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005/5 "2020-04-17T17:19:05Z")

</div>

> [@SKSG](#):
>
> P.S. - What is that .satisfies((s) function? I’m not finding any documentation on it, but I’m assuming it expects a ‘true’ value to be returned from any of the assertions being tested. What else can I use it for?

Postman uses the Expect assertion style from Chai, and [`.satisfy`/`.satisfies`](https://www.chaijs.com/api/bdd/#method_satisfy) is documented as part of the [Chai JavaScript API for `expect`](https://www.chaijs.com/api/bdd/).

> ### .satisfy(matcher[, msg])
> 
> - @param { Function } matcher
> - @param { String } msg _optional_
> 
> Invokes the given `matcher` function with the target being passed as the first argument, and asserts that the value returned is truthy.

To answer your other question…

> [@SKSG](#):
>
> I’ll try that, thanks! I just realized, couldn’t I also use an If → Else If statement as well? While the order of the conditions being met doesn’t really matter, it will potentially look through both attributes anyway to find the search term.

Yes, you can flip the logic if you like and use [`pm.expect.fail`](https://www.chaijs.com/api/bdd/#method_fail).

It would look something like this:

```js
pm.test('search is included in title or description', () => {
    if (!title.includes(search) && !description.includes(search)) {
        pm.expect.fail(`expected title or description to include "${search}"`)
    }
});

```

Best,

Kevin

---

<div class="post-metadata">

**Author:** ![SKSG](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SKSG](https://community.postman.com/u/SKSG)\
**Post date:** [April 17, 2020, 6:12pm UTC](https://community.postman.com/t/using-or-statement-to-validate-string-in-multiple-json-attributes/12005/6 "2020-04-17T18:12:26Z")

</div>

I thought of a third, “dirty” option: Since I’m essentially searching for a word within returned text, regardless of which attribute its from, I just created a variable equal to the combined response of title + description and searched though that. That way, I only have to satisfy 1 validation instead of using AND/OR statements.
