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

如何编写JOLT转换规则将数组拆分为多个对象?

JOLT转换规则实现数组展开

转换规则

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "data": {
          "*": {
            "value": {
              "*": {
                "@2,indicator": "[#2].indicator",
                "@": "[#2].value"
              }
            }
          }
        }
      }
    }
  }
]

规则说明

  • 逐层定位目标数组:通过data -> data访问到包含indicator和value的对象数组;
  • 遍历外层对象:用*匹配数组中的每个条目(即abc和def对应的对象);
  • 展开value数组:再次用*遍历每个对象的value数组元素;
  • 关联字段值:@2,indicator向上回溯2层获取当前条目的indicator值,[#2]生成连续的数组索引,确保每个value元素都和对应的indicator组成独立对象;
  • 赋值value字段:@直接引用当前遍历到的value数组元素值。

输入示例

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

输出结果

[
  {
    "indicator": "abc",
    "value": "1"
  },
  {
    "indicator": "abc",
    "value": "2"
  },
  {
    "indicator": "abc",
    "value": "3"
  },
  {
    "indicator": "abc",
    "value": "4"
  },
  {
    "indicator": "abc",
    "value": "5"
  },
  {
    "indicator": "def",
    "value": "6"
  },
  {
    "indicator": "def",
    "value": "7"
  },
  {
    "indicator": "def",
    "value": "8"
  },
  {
    "indicator": "def",
    "value": "9"
  },
  {
    "indicator": "def",
    "value": "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.09 04:16:42