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

如何使用JOLT将列格式JSON数组转换为行格式数组

JOLT转换方案:列结构JSON转行结构数组

输入JSON

{
  "data": {
    "fullentrydateGroup": [
      {
        "fullentrydateList": {
          "fullentrydate": [
            {
              "fullentrydate": "20240906",
              "position": "1"
            }
          ]
        },
        "index": "1"
      },
      {
        "fullentrydateList": {
          "fullentrydate": [
            {
              "fullentrydate": "20240907",
              "position": "1"
            }
          ]
        },
        "index": "2"
      }
    ],
    "creditamtGroup": [
      {
        "creditamtList": {
          "creditamt": [
            {
              "position": "1",
              "creditamt": "C"
            }
          ]
        },
        "index": "2"
      }
    ]
  }
}

目标输出JSON

{
  "statementEntries": [
    {
      "fullentrydate": "20240906",
      "creditamt": ""
    },
    {
      "fullentrydate": "20240907",
      "creditamt": "C"
    }
  ]
}

JOLT转换规范

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "fullentrydateGroup": {
          "*": {
            "fullentrydateList": {
              "fullentrydate": {
                "*": {
                  "fullentrydate": "statementEntries[&4].fullentrydate"
                }
              }
            }
          }
        },
        "creditamtGroup": {
          "*": {
            "creditamtList": {
              "creditamt": {
                "*": {
                  "creditamt": "statementEntries[&4].creditamt"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "statementEntries": {
        "*": {
          "creditamt": ""
        }
      }
    }
  }
]

转换逻辑说明

  1. Shift操作:
    • 遍历fullentrydateGroup的每一项,通过[&4]回溯层级获取当前项的数组索引(对应index数值),将fullentrydate值映射到statementEntries数组对应位置的对象中。
    • 用同样逻辑处理creditamtGroup,把creditamt值按索引匹配到对应行。
  2. Default操作:
    • 遍历statementEntries的所有行,为缺失creditamt字段的行补充空字符串,保证每行字段完整性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 09:32:40