Reputation: 159
I would like to filter an array based on another array values. I would like to filter the input array based on key value "KNVP-PARVW" is in the list of ["BP,SH,PY"]
here is the input:
[{
"KNVP-KUNNR": "100098",
"KNVP-VTWEG": "A1",
"KNVP-PARVW": "BP",
"KNVP-PARZA": "000",
"KNVP-KUNN2": "200115",
"KNVP-DEFPA": ""
},
{
"KNVP-KUNNR": "100098",
"KNVP-VTWEG": "A1",
"KNVP-PARVW": "SH",
"KNVP-PARZA": "001",
"KNVP-KUNN2": "200115",
"KNVP-DEFPA": ""
},
{
"KNVP-KUNNR": "100098",
"KNVP-VTWEG": "A1",
"KNVP-PARVW": "ZR",
"KNVP-PARZA": "000",
"KNVP-KUNN2": "256",
"KNVP-DEFPA": ""
}]
and here is my dataweave code:
%dw 2.0
var relationList=["BP,SH,PY"]
output application/json
---
payload filter ( relationList contains $."KNVP-PARVW" )
Upvotes: 1
Views: 2833
Reputation: 25664
While ["BP,SH,PY"]
is a list, it has only one element which is a string. To use contains() as you intend, it has to be a list of the valid values for $."KNVP-PARVW"
:
%dw 2.0
var relationList=["BP","SH","PY"]
output application/json
---
payload filter ( relationList contains $."KNVP-PARVW" )
Output:
[
{
"KNVP-KUNNR": "100098",
"KNVP-VTWEG": "A1",
"KNVP-PARVW": "BP",
"KNVP-PARZA": "000",
"KNVP-KUNN2": "200115",
"KNVP-DEFPA": ""
},
{
"KNVP-KUNNR": "100098",
"KNVP-VTWEG": "A1",
"KNVP-PARVW": "SH",
"KNVP-PARZA": "001",
"KNVP-KUNN2": "200115",
"KNVP-DEFPA": ""
}
]
Upvotes: 4
Reputation: 159
Got it the var relationList should be like below
var relationList="BP,SH,PY"
Upvotes: -1