有没有办法在jolt中为数组中的所有元素添加前缀?

问题描述 投票:0回答:1

我想向数组中的所有字段添加一个常量前缀,例如“0”。

这是输入:

{
  "input": [
    "1_ANY",
    "2_ANY",
    "3_ANY"
  ]
}

Output:

{
  "output" : [ "1", "2", "3" ]
}

预期输出:

{
  "output" : [ "01", "02", "03" ]
}

规格:

[
  {
    "operation": "shift",
    "spec": {
      "input": {
        "*": {
          "*_*": {
            "$(0,1)": "output"
          }
        }
      }
    }
  }

]

有没有办法为字符串数组中的所有元素添加常量前缀?

json transformation jolt
1个回答
0
投票

您可以将修改覆盖测试版规范添加到您创建的规范中以进行串联,如下所示:

[
  {
    "operation": "shift",
    "spec": {
      "input": {
        "*": {
          "*_*": {
            "$(0,1)": "output"
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "output": {
        "*": "=concat('0',@0)"
      }
    }
  }

]

或者您可以使用两个移位操作来完成,如下所示:

[
  {
    "operation": "shift",
    "spec": {
      "input": {
        "*": {
          "*_*": {
            "$": "0&(1,1)"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "output"
      }
    }
  }

]
© www.soinside.com 2019 - 2024. All rights reserved.