# JSONata filter array of strings

**URL:** <https://discourse.nodered.org/t/jsonata-filter-array-of-strings/76810>\
**Category:** General\
**Tags:** jsonata\
**Created:** [22 March 2023 10:24 UTC](https://discourse.nodered.org/t/jsonata-filter-array-of-strings/76810 "2023-03-22T10:24:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![protonmw](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@protonmw](https://discourse.nodered.org/u/protonmw)\
**Post date:** [22 March 2023 10:24 UTC](https://discourse.nodered.org/t/jsonata-filter-array-of-strings/76810/1 "2023-03-22T10:24:33Z")

</div>

Sometimes JSONata is so hard to understand...

how can i filter the string from the array that contains "bara" ?

```auto
["100.00barg","BAROMETER","101.00bara"]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 March 2023 10:30 UTC](https://discourse.nodered.org/t/jsonata-filter-array-of-strings/76810/2 "2023-03-22T10:30:23Z")

</div>

Assuming that array is in `msg.payload`, the following will return an array that only contains the values that include the text `bara`

```auto
[
 $filter($.payload, function($v) {
   $contains($v, 'bara')
 })
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [22 March 2023 10:37 UTC](https://discourse.nodered.org/t/jsonata-filter-array-of-strings/76810/3 "2023-03-22T10:37:49Z")

</div>

Or without calling the filter function and to return an array even if single item found [Path Operators · JSONata](https://docs.jsonata.org/path-operators#---filter)

```auto
$$.payload[$contains($,"bara")][]

```

---

<div class="post-metadata">

**Author:** ![protonmw](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@protonmw](https://discourse.nodered.org/u/protonmw)\
**Post date:** [22 March 2023 10:44 UTC](https://discourse.nodered.org/t/jsonata-filter-array-of-strings/76810/4 "2023-03-22T10:44:19Z")

</div>

I was struggling with the $... Thanks!

**$$.** payload[$contains( **$** ,"bara")]

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 April 2023 10:45 UTC](https://discourse.nodered.org/t/jsonata-filter-array-of-strings/76810/5 "2023-04-05T10:45:07Z")

</div>

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