json - 如何将 JSON 对象名称转换为元素名称?另外,删除嵌套对象?

标签 json mule-studio dataweave

我正在尝试使用 Dataweave 来改变这一点:

{
    "ConcurrentAsyncGetReportInstances": {
        "Max": 200,
        "Remaining": 200
    },
    "ConcurrentSyncReportRuns": {
        "Max": 20,
        "Remaining": 20
    },
    "DailyAnalyticsDataflowJobExecutions": {
        "Max": 50,
        "Remaining": 50
    },
    "DailyApiRequests": {
        "Max": 6175000,
        "Remaining": 6174972,
        "Ant Migration Tool": {
            "Max": 0,
            "Remaining": 0
        },
        "CLM_service_api": {
            "Max": 0,
            "Remaining": 0
        },
        "CRM_service_api": {
            "Max": 0,
            "Remaining": 0
        }
    },
    "DailyAsyncApexExecutions": {
        "Max": 325000,
        "Remaining": 324902
 }

进入此:

[
{
    "name":"ConcurrentAsyncGetReportInstances",
    "max":200,
    "remaining":200 
},
{
    "name":"ConcurrentSyncReportRuns",
    "max":"20",
    "remaining":"20"    
},
{
    "name":"DailyAnalyticsDataflowJobExecutions",
    "max":50,
    "remaining":50  
},
{
    "name":"DailyApiRequests",
    "max":6175000,
    "remaining":6174972 
},
{
    "name":"DailyAsyncApexExecutions",
    "max":325000,
    "remaining":324902  
}
]

另外 - 请注意,我不需要像 DailyApiRequests 中那样的任何嵌套值

我尝试过 map 功能,但不确定如何正确使用。我见过的所有例子似乎都没有显示这种情况。

最佳答案

使用 DataWeave

%dw 1.0
%input payload application/json
%output application/json
---
payload pluck ((value,key) -> {
    name: key,
    max: value.Max,
    remaining: value.Remaining
  } 
)

关于json - 如何将 JSON 对象名称转换为元素名称?另外,删除嵌套对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54057740/

相关文章:

java - 使用 Gson 将匿名 java 对象类型转换为 JSON

php mysql json 文件构成

curl - 如何使用 curl 从命令行界面 (CLI) 调用 Mule 的文件入站端点?

javascript - cvc-复合体类型.2.4。发现以元素 'dw:transform-message' 开头的无效内容

c# - 在 Web.API Controller 中自动反序列化为类似字符串的类

php - 当向 localhost 发出 GET 请求时和向远程主机发出 GET 请求时,json 编码数据的解析方式不同

soap - 使用Mule 3.5.1 EE Web服务使用者组件时如何获取SOAP Fault xml?

mule - 在 Dataweave 中将 TEXT 文件转换为 JSON

dataweave - 使用 p() 函数 mule 获取 dataweave 2.0 中的安全属性

Mule Dataweave 格式 :number