【问题标题】:Compare Object value with array in dataweave?将对象值与dataweave中的数组进行比较?
【发布时间】:2022-08-19 17:57:26
【问题描述】:

样本输入 1

{
  \"data\": [
    {
      \"a\": [
        {
          \"id\": 123
        }
      ],
      \"a1\": [],
      \"a3\": [],
      \"a4\": []
    },
    {
      \"b\": [
        {
          \"bid\": 133
        }
      ],
      \"b1\": [],
      \"b2\": []
    },
    {
      \"c\": [],
      \"c1\": [],
      \"d\": []
    }
  ]
}

样本输入 2:(基于它将过滤样本输入 1)

[
   \"d\",
   \"b\",
   \"b1\",
   \"a4\"
]

通过比较两个输入的值

场景:基于 2 输入中存在的对象名称需要从有效负载 1 中过滤掉对象。

预期的最终输出:

{
    \"data\": [{
        \"a\": [{
            \"id\": 123
        }],
        \"a1\": [],
        \"a3\": []
    },
    {
        \"b2\": []
    },
    {
        \"c\": [],
        \"c1\": []
    }]
}

示例代码:

%dw 2.0
output application/json 
---
payload.data map ((item, index) -> item - \"d\" - \"b\" - \"b1\" - \"a4\") //
 Note: This sample is working but but the values should be taken dynamically from the 2 input

任何帮助,将不胜感激。谢谢你。

    标签: dynamic dataweave mulesoft anypoint-studio


    【解决方案1】:

    试试这个:

    Payload 是您输入的样本输入 1。

    %dw 2.0
    output application/json
    var filterList = [ "d", "b", "b1", "a4" ]
    ---
    data: payload.data map {
        ($ -- filterList)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多