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

如何在JOLT中使用键值?拆解嵌套JSON并适配SQL数据库

JOLT实现嵌套JSON扁平化适配SQL数据库

需要将嵌套JSON拆解为扁平化结构以适配SQL数据库,原始JSON结构如下:

{
  "content": {
    "failedPerProductLineAndReason": {
      "Product1": {
        "Downsizing licenses is not allowed": 1
      }
    }
  }
}

期望转换后的扁平化结构:

{
  "ErrorType": "failedPerProductLineAndReason",
  "product": "Product1",
  "error": "Downsizing licenses is not allowed",
  "quantity": 1
}

JOLT转换规格

使用shift操作即可完成键值提取与映射,具体规格如下:

[
  {
    "operation": "shift",
    "spec": {
      "content": {
        "*": {
          "*": {
            "*": {
              "@": "quantity",
              "$": "error",
              "$2": "product",
              "$3": "ErrorType"
            }
          }
        }
      }
    }
  }
]

转换逻辑说明

  • 逐层定位嵌套节点:从content开始,用*通配符匹配各层级的所有键,适配同结构的多组数据
  • @:提取当前节点的数值,映射为quantity字段
  • $:提取当前节点的键名,映射为error字段
  • $2:向上回溯两层的键名(即产品名称),映射为product字段
  • $3:向上回溯三层的键名(即错误类型标识),映射为ErrorType字段

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 08:55:20