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

如何使用Jolt将二维数组转换为目标键值对对象?

二维数组转键值对对象的Jolt配置方案

需求说明

输入为包含表头数组和数据数组的二维结构,需将表头元素作为键、对应位置的数据元素作为值,生成目标键值对对象。

正确Jolt配置

[
  {
    "operation": "shift",
    "spec": {
      "1": {
        "*": {
          "@": "@(2,0[&1])"
        }
      }
    }
  }
]

配置逻辑解释

  • "1":定位到输入数组的第二个元素(数据数组,数组索引从0开始)
  • "*":遍历数据数组中的每一个元素
  • "@":指代当前遍历到的数据元素值
  • "@(2,0[&1])":向上回溯2层到根数组,取第一个元素(表头数组)中索引与当前数据元素索引&1匹配的元素,作为键名

验证效果

输入

[
  [
    "station_name",
    "station_longname"
  ],
  [
    "10 Mile Brook Dam Water Level Daily Value, South W",
    "10 Mile Brook Dam Water Level Daily Value, South West Region"
  ]
]

输出

{
  "station_name": "10 Mile Brook Dam Water Level Daily Value, South W",
  "station_longname": "10 Mile Brook Dam Water Level Daily Value, South West Region"
}

内容的提问来源于stack exchange,提问作者Drew Nicolette

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 11:57:10