【问题标题】:Get a child value and set as the parent value using JOLT使用 JOLT 获取子值并设置为父值
【发布时间】:2021-12-30 01:01:17
【问题描述】:

我有这个输入 JSON:

{
  "stores": {
    "1100": {
      "metric1": "27",
      "metric2": "3013775",
      "indicator": 8.96
    },
    "1200": {
      "metric1": "2",
      "metric2": "354418",
      "indicator": 5.64
    }
  }
}

并且需要将每个store的值转换成来自子indicator的值,像这样:

{
  "stores": {
    "1100": 8.96,
    "1200": 5.64
  }
}

我该怎么做?

【问题讨论】:

    标签: json jolt


    【解决方案1】:

    您可以像这样使用 shift 转换

    [
      {
        "operation": "shift",
        "spec": {
          "stores": {
            "*": {
              "indicator": "&2.&1"
            }
          }
        }
      }
    ]
    

    其中 "*" 表示 stores 对象的索引。例如,我们遍历 stores 对象的元素,将结果限制为 "indicator" 键的值,其中 &2 表示进入两个级别向上抓取键名("stores"),&1代表上一层抓取索引值("1100" ,“1200”)

    【讨论】:

    • 效果很好,谢谢!
    猜你喜欢
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    相关资源
    最近更新 更多