How to filter JSON message with multiple values of an array using Dataweave 2.0 Mule
Are you looking to filter keys in JSON messages with multiple values, multiple conditions of an array? Below Dataweave code helps you in applying filters with multiple values or multiple conditions.
Must Read: Remove objects with null values from the JSON payload in Mule

Input message:
[{
"Book": "BN1",
"Author": "A1",
"ID": 101,
"ISBN": 201
},
{
"Book": "BN2",
"Author": "A2",
"ID": 101
},
{
"Book": "BN3",
"Author": "A3",
"ISBN": 202
}
]
Dataweave Code:
%dw 2.0
output application/json
var filterArray = ["ID", "ISBN"]
---
payload map (obj,indexOfObj) ->
obj mapObject (value,key) -> {
("name": key) if (filterArray contains key as String ),
("value": value) if (filterArray contains key as String )
}
Output:
Also Read: How to use the filter, contains in DataWeave 2.0 on JSON array Mule 4
0 Comments