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

编写JOLT转换规范:将VT对象拆分为独立实体并关联元数据

JOLT转换规范调整方案

问题原因

你当前的输出会把同一ChannelData下的VT数据合并成数组,核心原因是shift操作中使用了[&4]作为目标对象的索引:

  • &4指向的是ChannelData数组的下标(从VT的*层级往上数,第4层是ChannelData数组的索引位)
  • 同一个ChannelData下的所有VT元素都会被映射到同一个[&4]对象中,JOLT会自动将重复字段的多个值合并为数组。

正确的JOLT转换规范

要让每个VT对象成为独立的顶层对象,需要将目标数组的索引改为[](自动为每个VT元素创建新的数组项),同时正确引用上层的字段:

[
  {
    "operation": "shift",
    "spec": {
      "StationDataList": {
        "StationData": {
          "ChannelData": {
            "*": {
              "Values": {
                "VT": {
                  "*": {
                    "@(4,stationId)": "[].stationId",
                    "@(4,timezone)": "[].timezone",
                    "@(4,name)": "[].name",
                    "@(1,channelId)": "[].channelId",
                    "t": "[].t",
                    "content": "[].content"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

字段引用说明

  • @(4,stationId):从当前VT的*层级往上数4层,定位到StationData节点,获取stationId值
  • @(1,channelId):从当前VT的*层级往上数1层,定位到当前ChannelData节点,获取channelId值
  • []:JOLT会自动为每个VT元素生成一个新的顶层数组对象,将对应字段逐一填充

预期输出

执行上述规范后,输出会是包含6个独立对象的数组(每个VT对应一个):

[
  {"stationId":"123","timezone":"+01:00","name":"stationName","channelId":"channelId1","t":"2023-12-13T00:15:00","content":-1},
  {"stationId":"123","timezone":"+01:00","name":"stationName","channelId":"channelId1","t":"2023-12-13T00:30:00","content":-2},
  {"stationId":"123","timezone":"+01:00","name":"stationName","channelId":"channelId1","t":"2023-12-13T00:45:00","content":-3},
  {"stationId":"123","timezone":"+01:00","name":"stationName","channelId":"channelId2","t":"2023-12-13T01:00:00","content":1},
  {"stationId":"123","timezone":"+01:00","name":"stationName","channelId":"channelId2","t":"2023-12-13T02:00:00","content":2.5},
  {"stationId":"123","timezone":"+01:00","name":"stationName","channelId":"channelId2","t":"2023-12-13T03:00:00","content":3}
]

内容的提问来源于stack exchange,提问作者Maxim Novakovski

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 13:59:55