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

如何用Jolt去除JSON中properties数组内的嵌套数组

Jolt转换方案:去除brand的嵌套数组

输入示例

{
  "properties": [
    {
      "name": "item1",
      "brand": [
        {
          "brandName": "BrandA",
          "brandId": "123"
        }
      ]
    },
    {
      "name": "item2",
      "brand": [
        {
          "brandName": "BrandB",
          "brandId": "456"
        }
      ]
    }
  ]
}

目标输出

{
  "properties": [
    {
      "name": "item1",
      "brand": {
        "brandName": "BrandA",
        "brandId": "123"
      }
    },
    {
      "name": "item2",
      "brand": {
        "brandName": "BrandB",
        "brandId": "456"
      }
    }
  ]
}

Jolt转换规范

[
  {
    "operation": "shift",
    "spec": {
      "properties": {
        "*": {
          "name": "properties[&1].name",
          "brand": {
            "[0]": "properties[&2].brand"
          }
        }
      }
    }
  }
]

规则说明

  • properties.* 遍历原properties数组中的每一个元素
  • &1 代表当前遍历的数组索引,保证输出元素的位置和原数组一致
  • brand[0] 提取brand嵌套数组里的第一个元素,直接赋值给输出中的brand字段,替代原来的数组结构

如果你的brand数组包含多个元素,可根据需求调整[0]:比如要保留所有元素就改成*,要取指定位置就替换为对应索引值。

内容的提问来源于stack exchange,提问作者Katja Bürger

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 04:27:03