简体   繁体   中英

how to get string values from list of maps in dataweave 2.0?

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.

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)
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM