json - JOLT 转换 - 将新元素命名为数组元素的值
问题描述
我不确定这是否可以通过颠簸转换来实现。但我想将随机顺序的 json 更改为具体名称:
输入json:
{
"scheduler" : {
"schedulerInfo" : {
"usedCapacity" : 50.0,
"queueName" : "root",
"queues" : {
"queue" : [ {
"type" : "capacitySchedulerLeafQueueInfo",
"usedCapacity" : 10.0,
"queueName" : "jupyter"
}, {
"type" : "capacitySchedulerLeafQueueInfo",
"usedCapacity" : 25.0,
"queueName" : "spark"
},
{
"type" : "capacitySchedulerLeafQueueInfo",
"usedCapacity" : 15.0,
"queueName" : "dremio"
}
} ]
}
}
}
}
期望的结果:
{
"rootUsedCapacity": 50.0,
"jupyterUsedCapacity": 10.0,
"sparkUsedCapacity": 25.0,
"dremioUsedCapacity":15.0
}
我知道如何使其成为静态,但我不知道如何将“queueName”的值添加到新的属性 &value+UsedCapacity : &ArrayValue
静态解决方案:
[
{
"operation": "shift",
"spec": {
"scheduler": {
"schedulerInfo": {
"usedCapacity": "rootUsedCapacity",
"queues": {
"queue": {
"0": {
"usedCapacity": "jupyterUsedCapacity"
},
"1": {
"usedCapacity": "sparkUsedCapacity"
},
"2": {
"usedCapacity": "dremioUsedCapacity"
}
}
}
}
}
}
}
]
解决方案
将 queueName 与 UsedCapacity 字符串连接,然后将新创建的节点与 usedCapacity 移位,
[
{
"operation": "modify-default-beta",
"spec": {
"scheduler": {
"schedulerInfo": {
"queues": {
"queue": {
"*": {
"queueNameNew": "=concat(@(1,queueName),'UsedCapacity')"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"scheduler": {
"schedulerInfo": {
"usedCapacity": "rootUsedCapacity",
"queues": {
"queue": {
"*": {
"usedCapacity": "@(1,queueNameNew)"
}
}
}
}
}
}
}
]
推荐阅读
- api - 没有与 DB 匹配的数据时的 HTTP 状态码响应
- ansible - ansible 对来自多个主机的结果进行迭代以提取特定的键值
- reactjs - React 延迟服务器端渲染
- java - 如何使用 JAXB 防止 XML 实体注入
- java - 在namedParameterJdbcTemplate.batchUpdate(query..)中出现错误,在查询中使用in-clause时
- javascript - What happens to other observables when rxjs.race() has been won?
- regex - 正则表达式在“/”之前返回所有字符,但如果有 2 个“/”,则在此之前返回所有字符
- android - Funtouch OS 中的 Play 服务视觉 API
- android - 对于我在广播接收器中指定的任何条件,我都看不到 toast 消息
- java - Testng && Spring上下文单元测试->测试方法前后执行sql