【问题标题】:How to create a json message from 2 different json message using Dataweave如何使用 Dataweave 从 2 个不同的 json 消息创建 json 消息
【发布时间】:2017-11-12 11:24:48
【问题描述】:

我想从 2 个不同的 Json 消息创建一个 json 消息。两个输入消息都来自流变量。如何使用 Dataweave 完成。

消息 1:

    [

     {
         "userId": 11,
         "name": "ABC",
         "age": 30
     },

     {
         "userId": 44,
         "name": "XYZ",
         "age": 30
     }

     ]

消息 2:

 [

 {
     "userId": 11,
     "Address": "BLR"
 },
 {
     "userId": 44,
     "Address": "CCU"
 }

 ]

预期输出:

[

 {
     "userId": 11,
     "name": "ABC",
     "Address": "BLR"
 },
 {
     "userId": 44,
     "name": "XYZ",
     "Address": "CCU"
 }

 ]

提前谢谢你, 尼特什

【问题讨论】:

    标签: mule anypoint-studio dataweave


    【解决方案1】:

    您可以使用查找代替过滤器,因为使用过滤器会产生性能开销。 试试这个

    %dw 1.0
    %output application/json
     %var adressLookup = {(  flowVars.data map  {
        ($.userId ++ "") : $
     })}
     ---
    payload map {
        userId : $.userId,
        name : $.name,
        Address : adressLookup[$.userId ++ ""].Address
    }
    

    payload 是 message1,flowVars.data 是 message2

    P.S : 我使用 $.userId ++ "" 作为 hashmap 的字符串格式的键,有些数字键不适用于 weave hashmap。

    也可以参考Merge two json payload with dataweave

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      参考this 文章。似乎是您用例的完美解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-20
        • 2011-11-24
        • 2019-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多