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

JOLT新手求助:如何将类表格JSON转换为规范JSON?

JOLT转换类表格JSON解决方案

输入示例

{
  "Sections": [
    {
      "Title": "用户信息",
      "Rows": [
        {
          "RowType": "Header",
          "Cells": [{"Value": "字段"}, {"Value": "内容"}]
        },
        {
          "RowType": "Data",
          "Cells": [{"Value": "姓名"}, {"Value": "张三"}]
        },
        {
          "RowType": "Data",
          "Cells": [{"Value": "年龄"}, {"Value": "30"}]
        }
      ]
    },
    {
      "Title": "订单信息",
      "Rows": [
        {
          "RowType": "Header",
          "Cells": [{"Value": "字段"}, {"Value": "内容"}]
        },
        {
          "RowType": "Data",
          "Cells": [{"Value": "订单号"}, {"Value": "OD20240501"}]
        },
        {
          "RowType": "Data",
          "Cells": [{"Value": "金额"}, {"Value": "199"}]
        }
      ]
    }
  ]
}

JOLT转换规范

[
  {
    "operation": "shift",
    "spec": {
      "Sections": {
        "*": {
          "Rows": {
            "*": {
              "RowType": {
                "Data": {
                  "@(2,Cells[0].Value)": "@(3,Title).@(2,Cells[1].Value)"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "&2.&"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": "ONE"
      }
    }
  }
]

输出结果

{
  "用户信息": {
    "姓名": "张三",
    "年龄": "30"
  },
  "订单信息": {
    "订单号": "OD20240501",
    "金额": "199"
  }
}

关键步骤说明

  • 第一步shift:遍历所有Section,过滤掉RowType为Header的行,同时把数据行的Cells[0].Value暂存为值,Cells[1].Value暂存为键,关联到对应Section的Title下
  • 第二步shift:反转暂存的键值对,把Cells[0].Value设为最终的键,Cells[1].Value设为对应的值
  • cardinality操作:确保每个字段只保留唯一值,避免重复行导致的数组结构

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 13:25:18