How to use the filter, contains in Dataweave 2.0 on JSON array Mule 4
The filter expression in Dataweave 2.0 evaluates the given condition and returns an array from the array of values. The contains evaluates an expression and returns a boolean value that is either true or false. contains functions in Dataweave can be applied on an array or string as well
Example 1: Filter the JSON Payload using contains
%dw 2.0
output application/json
---
payload.errors filter ($.status contains 503) map {
status: $.status,
source: $.source,
detail:$.detail
}
Output:
🧐 Also read: Do you know the use of parseURI in Dataweave
Example 2: Filter the JSON Payload using <, >, == operators
%dw 2.0
output application/json
---
payload.errors filter $.status >=500 map {
status: $.status,
source: $.source,
detail:$.detail
}
Output:
🧐 Also read: When do we use p() function in Dataweave 2.0
0 Comments