1
votes

I have input payload coming like this -

[ { "a": "" }, { "a": "abc" }, { "a": "pqr" }, { "a": "xyz" } ] and desired output is abc,pqr,xyz

I tried following dwl but couldn't succeed. Here is the code snippet

%dw 2.0

output application/json

query : payload filter ($.a != '') map ( $.a )

Can someone please help me with the dataweave ? Thanks.

2

2 Answers

3
votes

If your desired output is the string "abc,pqr,xyz":

%dw 2.0
output application/json
---
payload filter ($.a != "") map ($.a) joinBy  ","

If you are trying to get the array ["abc", "pqr", "xyz"]: Your code is fine...

%dw 2.0
output application/json
---
payload filter ($.a != "") map ($.a)
0
votes
query: joinBy(payload.a filter $ !="", ',')
  1. First select all 'a' fields to return new array of just values.
  2. Filter the list for "".
  3. Use joinBy function to append array values with a comma.