# $in Clause in Advanced Query Bad Validation Error

**URL:** <https://forums.losant.com/t/in-clause-in-advanced-query-bad-validation-error/5470>\
**Category:** Bug Report\
**Created:** [May 10, 2024, 9:46pm UTC](https://forums.losant.com/t/in-clause-in-advanced-query-bad-validation-error/5470 "2024-05-10T21:46:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Travis\_Rhoden](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@Travis\_Rhoden](https://forums.losant.com/u/Travis_Rhoden)\
**Post date:** [May 10, 2024, 9:46pm UTC](https://forums.losant.com/t/in-clause-in-advanced-query-bad-validation-error/5470/1 "2024-05-10T21:46:13Z")

</div>

The query being used.

```auto
{
  "$and": [
    {
      "scheduleId": {
        "$in": "{{data.query.id}}",
        "$ci": true
      }
    }
  ]
}

```

Returns a validation error at the output location -  
`"message": "scheduleId: value for $in must be an array"`

A simple mutate that pushes the type (`{{typeof data.query.id}}`) outputs `array`.

A thing cannot be an array and not an array at the same time.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [May 10, 2024, 10:22pm UTC](https://forums.losant.com/t/in-clause-in-advanced-query-bad-validation-error/5470/2 "2024-05-10T22:22:01Z")

</div>

Hi @Travis_Rhoden, and welcome to the Losant Forums.

The default Handlebars behavior when using an expression to evaluate an array is similar to the [JavaScript Array.prototype.toString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) method. I couldn’t find this in their documentation but you can reproduce it on their website:

[https://handlebarsjs.com/examples/literal-segments.html](https://handlebarsjs.com/examples/literal-segments.html)

 ![Screenshot 2024-05-10 at 6.14.09 PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/8/8207f1ce9fbd23d2ebec2b5e3e9844f137581a33.png)

So in your case, `data.query.id` may be an array but rendering it as you are in this template will output it as a comma-separated string - and if it did output as an array, it would still be treated as a string in the request because of the quotes `""` you wrapped the value with.

What you want to use instead is Losant’s [`{{jsonEncode}}` helper](https://docs.losant.com/workflows/accessing-payload-data/#jsonencode-val-spacerstr) like so:

```json
{
  "$and": [
    {
      "scheduleId": {
        "$in": {{jsonEncode data.query.id}},
        "$ci": true
      }
    }
  ]
}

```

 ![Screenshot 2024-05-10 at 6.19.40 PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/e/e5bd50152b275e881999ef9bbd21db7e887cbe3b.png)

I encourage you to test your templates out in our built-in [workflow template tester](https://docs.losant.com/workflows/platform-template-tester/) if you run into these kinds of unexpected issues in the future.

Hopefully this helps. Let us know if you have any other questions.
