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

求助:复杂嵌套JSON的Jolt转换实现指定扁平化输出

Jolt嵌套JSON转扁平化输出方案(含DistributionChannelCode数组提取)

输入JSON示例

{
  "Root": {
    "Header": {
      "OrderNo": "SO-001",
      "CustomerID": "CUST-100"
    },
    "Details": {
      "Items": [
        {
          "ItemCode": "ITEM-01"
        }
      ],
      "DistributionChannels": [
        {
          "DistributionChannelCode": "D1",
          "Description": "线上渠道"
        },
        {
          "DistributionChannelCode": "D2",
          "Description": "线下门店"
        }
      ]
    }
  }
}

期望输出

{
  "OrderNo": "SO-001",
  "CustomerID": "CUST-100",
  "ItemCode": "ITEM-01",
  "DistributionChannelCode": ["D1", "D2"]
}

修正后的Jolt转换规则

[
  {
    "operation": "shift",
    "spec": {
      "Root": {
        "Header": {
          "OrderNo": "OrderNo",
          "CustomerID": "CustomerID"
        },
        "Details": {
          "Items": {
            "*": {
              "ItemCode": "ItemCode"
            }
          },
          "DistributionChannels": {
            "*": {
              "DistributionChannelCode": "DistributionChannelCode[]"
            }
          }
        }
      }
    }
  }
]

关键规则说明

  • 用shift操作符完成字段映射与结构扁平化,将嵌套层级的字段直接映射到顶层
  • DistributionChannels.*通配符遍历所有渠道对象,通过DistributionChannelCode[]的方括号语法,自动将每个匹配到的渠道代码收集为数组
  • 若输入存在多层级数组字段,可通过*通配符遍历数组元素完成批量映射

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 16:25:35