从组合的 json 列表创建单个 json

Creating a single json from a combined json list

我在 for 循环中得到多个 json 文件,每个循环中的每个 json 都采用以下格式:

{
    "myproperties": {
        "http.port": "8088",
        "http.base": "/abc",
        "http.path": "test"
    },
    "information": [{
        "abc": {
            "key1": "ghghghghgh"
        },
        "efg": {
            "key1": "value1"
        }
    }]
}

{
    "myproperties": {
        "http.port": "6789",
        "db.base": "tat",
        "db.path": "ghghghg"
    },
    "information": [{
        "efg": {
            "key1": "ghghghghgh"
        },
        "ijk": {
            "key1": "value1"
        }
    }]
}

等等…….

I manage to combine for 循环外列表中的所有 json 和组合 json 列表如下所示:

    [{
    "myproperties": {
        "http.port": "8088",
        "http.base": "/abc",
        "http.path": "test"
    },
    "information": [{
        "abc": {
            "key1": "ghghghghgh"
        },
        "efg": {
            "key1": "value1"
        }
    }]
}, 
 {
    "myproperties": {
        "http.port": "6789",
        "db.base": "tat",
        "db.path": "ghghghg"
    },
    "information": [{
        "efg": {
            "key1": "ghghghghgh"
        },
        "ijk": {
            "key1": "value1"
        }
    }]
}]

现在我想**single** json output output json 以下格式的东西:

 {
    "myproperties": {
        "http.port": "6789",
        "db.base": "tat",
        "db.path": "ghghghg",
        "http.base": "/abc",
        "http.path": "test"
    },
    "information": [{
            "efg": {
                "key1": "ghghghghgh"
            },
            "ijk": {
                "key1": "value1"
            }
        },
        {
            "abc": {
                "key1": "ghghghghgh"
            },
            "efg": {
                "key1": "value1"
            }
        }
    ]
 }

请注意 myproperties 部分只有 uniquedistinct 节点。 我不确定如何从 dataweave 开始……任何指针将不胜感激,

我尝试了以下方法:

%dw 1.0
%output application/json skipNullOn="everywhere",encoding="UTF-8"
---
payload map {

    myproperties: $.myproperties,
    information: $.information

}

但不工作

谢谢

尝试使用 mapObject 来组合属性,并尝试将信息数组变平为单个数组,例如

%dw 1.0
%output application/json
---
{
    myproperties : payload.myproperties mapObject $ ,
    information : (flatten payload.information) 
}

HTH

更新:- 对于不同的属性,您必须首先获取不同的属性,然后映射所有不同的属性。但是您可能会丢失重复的属性。参考以下

%dw 1.0
%output application/json
%var distinctProperties =((payload.myproperties mapObject $) pluck $$)  distinctBy $ 
%var aggregatedPropertiesMap =  (payload.myproperties mapObject $)
---
{
    myproperties : {( distinctProperties map { // interate over distinct properties 
        ($) : aggregatedPropertiesMap[$]    // map property as key and fetch its value from aggregatedPropertiesMap
    })} ,
    information : (flatten payload.information) 
}