Mule Dataweave:在将 json 转换为 xml 时使用动态密钥

Mule Dataweave: using dynamic key while transforming json to xml

我正在尝试使用 Mule dataweave 转换器将 JSON 转换为 XML。 JSON 有效载荷的键名之一是动态的,它取决于您提供给 JSON 有效载荷的输入。请看我使用

line #40
value: payload.quotes.INR.midpoint

解析数据。 INR 基本上是 payload 的目标货币,目标货币值为 line #39:

target_currency: payload.meta.effective_params.quote_currencies[0]

所以在分配 值时 我想使用这样的东西:

value: payload.quotes.($(payload.meta.effective_params.quote_currencies[0])).midpoint

Mulesoft dataweave transformer 完全可以做到这一点吗?或者,如果没有,那么您能否提出任何巧妙的解决方案?

是的,用方括号[]按键查图:

exchange: {
        source_currency: payload.base_currency,
        target_currency: payload.meta.effective_params.quote_currencies[0],
        value: payload.quotes[payload.meta.effective_params.quote_currencies[0]].midpoint
    }