You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写JOLT转换规则将数组值拆分为多个JSON键?

JOLT转换规范

以下是实现需求的JOLT转换规范:

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "data": {
          "*": {
            "indicator": "[&1].indicator",
            "value": {
              "*": "[&2].value&(1,1)"
            }
          }
        }
      }
    }
  }
]

转换说明

  • shift操作负责重新组织JSON结构
  • data.data.*遍历原始数组中的每个对象
    • indicator直接映射到目标数组对应位置的indicator字段
    • value数组中的每个元素,通过&(1,1)获取数组索引(从0开始,自动加1后生成1-5的序号),以此创建value1到value5的字段,并将对应值映射到目标对象中

验证示例

输入JSON:

{
  "data": {
    "data": [
      {
        "indicator": "abc",
        "value": ["1","2","3","4","5"]
      },
      {
        "indicator": "def",
        "value": ["6","7","8","9","10"]
      }
    ]
  }
}

输出JSON:

[
  {
    "indicator": "abc",
    "value1": "1",
    "value2": "2",
    "value3": "3",
    "value4": "4",
    "value5": "5"
  },
  {
    "indicator": "def",
    "value1": "6",
    "value2": "7",
    "value3": "8",
    "value4": "9",
    "value5": "10"
  }
]

内容的提问来源于stack exchange,提问作者Duc Nguyen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 15:13:08