【问题标题】:How can I add all the values in array with jolt?如何使用 jolt 添加数组中的所有值?
【发布时间】:2022-11-05 04:24:54
【问题描述】:

输入

{
  "accounts": {
    "canara": 1,
    "sbi": 0,
    "axis": 1,
    "hdfc": 0
  }
}

预期产出

{
  "canara": 1,
  "sbi": 0,
  "axis": 1,
  "hdfc": 0,
  "total accounts": 2
}

我希望将所有帐户的总和添加到“总帐户”中。如何通过 jolt 实现这一目标?

【问题讨论】:

    标签: java arrays json jolt


    【解决方案1】:

    该规范应该有效:

    [
      {
        "operation": "shift",
        "spec": {
          "accounts": {
            "*": [
              ".&",
              "accountsAccumulator"
            ]
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "total accounts": "=intSum(@(1,accountsAccumulator))"
        }
      },
      {
        "operation": "shift",
        "spec": {
          "accountsAccumulator": null,
          "*": "&"
        }
      }
    ]
    

    看一下:

    【讨论】:

      【解决方案2】:

      我使用这个解决方案

      [
       // sum all fields and create a new field
        {
          "operation": "modify-overwrite-beta",
          "spec": {
            "accounts": {
              "total accounts": "=intSum(@(1,canara),@(1,sbi),@(1,axis),@(1,hdfc))"
            }
          }
        },
        {
          //extract all field of the account
          "operation": "shift",
          "spec": {
            "accounts": {
              "*": "&"
            }
          }
        }
      ]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-17
        • 1970-01-01
        • 2021-06-22
        • 2011-02-20
        • 2017-01-24
        相关资源
        最近更新 更多