Dataweave JSON过滤器

时间:2018-07-19 10:58:36

标签: mule dataweave mule-esb

我正在尝试根据其中一个字段从JSON请求中选择数据

[
    {
        "Field1": "data1",
        "Field2": "set1",
        "Field3": "reset1"
    },
    {
        "Field1": "data2",
        "Field2": "set2",
        "Field3": "reset2"
    },
    {
        "Field1": "data3",
        "Field2": "set3",
        "Field3": "reset3"
    },
    {
        "Field1": "data4",
        "Field2": "set4",
        "Field3": "reset4"
    }
]

我想选择field3的字符串值,其中field2是“ set3”。那就是“ reset3”。

我尝试过的DWL:

payload.Field3 filter (payload.Field2 ==["set3"])

2 个答案:

答案 0 :(得分:1)

您可以这样过滤:

<logger level="ERROR" message="Field3:::: #[(payload filter ($.Field2 =='set3'))[0].Field3]" />

自数组选择器[0]起,过滤器将返回数组。如果可能有多个结果,您可能需要更改表达式。

答案 1 :(得分:0)

使用可以使用此DW表达式:

%dw 1.0
%output application/json
---
payload filter ($.Field2=="set3") map {
    Field3: $.Field3
}

结果:

[
   {"Field3": "reset3"}
]