简体   繁体   English

如何从dataweave 2.0中的地图列表中获取字符串值?

[英]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 [{“ a”:“”},{“ a”:“ abc”},{“ a”:“ pqr”},{“ a”:“ xyz”}]并且期望的输出是abc,pqr,xyz

I tried following dwl but couldn't succeed. 我尝试跟随dwl,但无法成功。 Here is the code snippet 这是代码片段

%dw 2.0 %dw 2.0

output application/json 输出应用程序/ json

query : payload filter ($.a != '') map ( $.a ) 查询:有效负载过滤器($ .a!='')映射($ .a)

Can someone please help me with the dataweave ? 有人可以帮我做数据编织吗? Thanks. 谢谢。

If your desired output is the string "abc,pqr,xyz": 如果所需的输出是字符串“ 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... 如果您尝试获取数组[“ abc”,“ pqr”,“ xyz”]:您的代码很好...

%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. 首先选择所有“ a”字段以返回新的正值数组。
  2. Filter the list for "". 过滤列表中的“”。
  3. Use joinBy function to append array values with a comma. 使用joinBy函数可将数组值附加逗号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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