我看到文档说
Multi-value .*keyName Array of values of any matching keys
Descendants ..keyName Array of values of any matching descendant keys
但是我仍然不明白区别。
payload.breakfast_menu.food -> First food element
payload.breakfast_menu.*food -> List of food elements
payload.breakfast_menu.*name -> Nothing
payload.breakfast_menu..name -> List of all product name values
如果有此输入:
{
"id": 1,
"id": 11,
"secondLevel": {
"id": 2,
"id": 22,
"thirdLevel": {
"id": 3,
"id": 33
}
}
}
和此脚本:
{ "allTheId" : payload..*id, //all the ID "descendant": payload..id, //first occurrence of "id" in each level "multivalue": payload.*id, //all occurrence of "id" in the current level (the first level) "multivalueSecondLevel": payload.secondLevel.*id //all occurrence of "id" in the current level (the second level) }
它将生成此输出:
{ "allTheId": [ 1, 11, 2, 22, 3, 33 ], "descendant": [ 1, 2, 3 ], "multivalue": [ 1, 11 ], "multivalueSecondLevel": [ 2, 22 ] }
https://docs.mulesoft.com/mule-runtime/4.2/dataweave-cookbook-extract-data#descendants中的更多详细信息