简体   繁体   English

骡问题映射有效载荷 dataweave 2.0

[英]Mule issue mapping payload dataweave 2.0

I am trying to map the below json payload to only show dates with "999" value.我正在尝试 map 下面的 json 有效负载仅显示具有“999”值的日期。 Below is my payload下面是我的有效载荷

[ 
 {
  "Delivery Date": "16",
  "17/01/2018": "0",
  "18/01/2018": "999",
  "19/01/2018": "999",
  "20/01/2018": "0",
  "29/01/2018": "999",
  "18/02/2018": "0",
  "19/02/2018": "999",
  "20/02/2018": "999",
  "03/03/2018": "999"
 }
]

And my desired output is而我想要的 output 是

{ 
  "available_date": [ 
    "18/01/2018", 
    "19/01/2018, 
    "29/01/2018", 
    "19/02/2018", 
    "20/02/2018", 
    "03/03/2018"
  ],
  "message": "" 
}

Thanks for any advice!感谢您的任何建议!

I have tried this.我试过这个。

Approach 1 MapObject ,Pluck方法 1 MapObject ,Pluck

%dw 2.0
output application/json
---
{
"available_date":
    (payload mapObject ((value, key, index) -> ((key): (value)) if (value == "999")) pluck $$),
"message":""
}

Approach 2 FilterObject , keysOf方法 2 FilterObject , keysOf

%dw 2.0
output application/json
---
{
"available_date": keysOf(payload filterObject ((value, key) -> value == "999")),
"message":""
}

Output Output

{
  "available_date": [
    "18/01/2018",
    "19/01/2018",
    "29/01/2018",
    "19/02/2018",
    "20/02/2018",
    "03/03/2018"
  ],
  "message": ""
}

Alternative using filterObject and keysOf :使用filterObjectkeysOf替代方法:

%dw 2.0
output application/json
---
{
    'available_date' : keysOf(payload filterObject ((value, key, index) -> value contains "999")),
    message: ""
}

The other solutions are good.其他解决方案都很好。 Just for completeness I'll contribute one using filterObject() then pluck().为了完整起见,我将使用 filterObject() 然后 pluck() 贡献一个。

%dw 2.0
output application/json
---
{
    available_date: payload 
                        filterObject ($ == "999")
                        pluck ((value, key, index) -> key),
    message: ""
}

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

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