Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

contains

contains(Array<T>, Any): Boolean

Indicates whether an array contains a given value. Returns true or false.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
ContainsRequestedItem: payload.root.*order.*items contains "3"
Input

        
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <order>
      <items>155</items>
    </order>
    <order>
      <items>30</items>
    </order>
    <order>
      <items>15</items>
    </order>
    <order>
      <items>5</items>
    </order>
    <order>
      <items>4</items>
      <items>7</items>
    </order>
    <order>
      <items>1</items>
      <items>3</items>
    </order>
    <order>
        null
    </order>
</root>
Output

        
     
1
2
3
{
  "ContainsRequestedItem": true
}
contains(String, String): Boolean

Indicates whether a string contains a given substring. Returns true or false.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
ContainsString: payload.root.mystring contains "me"
Input

        
     
1
2
3
4
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <mystring>some string</mystring>
</root>
Output

        
     
1
2
3
{
  "ContainsString": true
}
contains(String, Regex): Boolean

Indicates whether a string contains a match to a given regular expression. Returns true or false.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
ContainsString: payload.root.mystring contains /s[t|p]rin/
Input

        
     
1
2
3
4
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <mystring>A very long string</mystring>
</root>
Output

        
     
1
2
3
{
  "ContainsString": true
}