首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JOLT转换-将新元素命名为数组元素的值

JOLT转换-将新元素命名为数组元素的值
EN

Stack Overflow用户
提问于 2020-09-08 18:10:21
回答 1查看 56关注 0票数 0

我不确定使用jolt转换是否可能做到这一点。但我想将随机顺序的json更改为具体名称:

输入json:

代码语言:javascript
复制
{
  "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"
          }
        } ]
      }
    }
  }
}

期望的结果:

代码语言:javascript
复制
{
"rootUsedCapacity": 50.0,
"jupyterUsedCapacity": 10.0,
"sparkUsedCapacity": 25.0,
"dremioUsedCapacity":15.0
}

我知道如何将其设置为静态的,但我不知道如何将"queueName“的值添加到新属性&value+UsedCapacity:&ArrayValue

静态解决方案:

代码语言:javascript
复制
[
  {
    "operation": "shift",
    "spec": {
      "scheduler": {
        "schedulerInfo": {
          "usedCapacity": "rootUsedCapacity",
          "queues": {
            "queue": {
              "0": {
                "usedCapacity": "jupyterUsedCapacity"
              },
              "1": {
                "usedCapacity": "sparkUsedCapacity"
              },
              "2": {
                "usedCapacity": "dremioUsedCapacity"
              }
            }
          }
        }
      }
    }
  }
]
EN

回答 1

Stack Overflow用户

发布于 2020-09-09 17:33:48

将queueName与usedCapacity字符串拼接,然后将新创建的节点与UsedCapacity进行移位。

代码语言:javascript
复制
[
  {
    "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)"
              }
            }
          }
        }
      }
    }
  }
]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63791699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档