Mulesoft Dataweave将mapObject的键转换为小写 [英] Mulesoft Dataweave Converting the key of a mapObject to lower case

查看:110
本文介绍了Mulesoft Dataweave将mapObject的键转换为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设以下json带有大写的KEY1和KEY2。 KEY1和KEY2需要转换为小写

Assume the following json with KEY1 and KEY2 in caps. KEY1 and KEY2 needs to be converted to lower case

 {
    "KEY1": {
        "subkey1": "subval1",
        "subkey2": "subval2"
    },
    "KEY2": {
        "subkey1": "subval1",
        "subkey2": "subval2"
    }
  }

这需要转换为下面的json使用数据编织。

this needs to be converted to the following json using data weave.

 {
    "key1": {
        "subkey1": "subval1",
        "subkey2": "subval2"
    },
    "key2": {
        "subkey1": "subval1",
        "subkey2": "subval2"
    }
  }

我尝试了以下DW语法,但没有用

I tried the following DW syntax, but it did not work

result : payload mapObject (
  lower '$$':$
)


推荐答案

如果将表达式用括号括起来,则尝试的DW应该可以工作。这样可以确保首先将 lower 运算符应用于每个键,然后在映射中使用该值。因此,对于您的示例:

The DW you tried should work if you wrap the expression in parenthesis. This ensures that the lower operator is applied to each of the keys first and then that value is used in the map. So for your example:

%dw 1.0
%output application/json
---
{
    result : payload mapObject (
        (lower '$$') : $
    )
}

有趣的是,我在使用以下消息的转换消息中收到错误(输入不匹配':'期望')')这种DW语法,但我能够在没有Anypoint Studio抱怨的情况下运行项目,并且DW运行良好。它在MEL中也可以使用以下代码:

Interestingly enough, I get an error (mismatched input ':' expecting ')') in my Transform Message using this DW syntax but I am able to run the project without complaints from Anypoint Studio and the DW runs fine. It also works in MEL with the following:

#[dw("{result : payload mapObject ( (lower  '$$' ) : $)}", 'application/json')]

希望有帮助!

这篇关于Mulesoft Dataweave将mapObject的键转换为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆