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

如何无需额外Shift操作,在Jolt中合并映射并生成totalQuantity列表?

优化Jolt Spec实现单步合并映射并生成totalQuantity

优化后的单次Shift操作Jolt Spec

[
  {
    "operation": "shift",
    "spec": {
      "orders": {
        "*": {
          "orderId": "orderId",
          "order_parts": "order_parts",
          "order_parts": {
            "*": {
              "items": {
                "*": {
                  "quantity": "totalQuantity[]"
                }
              }
            }
          }
        }
      }
    }
  }
]

输入JSON

{
  "orders": [
    {
      "orderId": "10001",
      "order_parts": [
        {
          "id": "00001",
          "items": [
            {
              "quantity": 1,
              "price": 20
            },
            {
              "quantity": 1,
              "price": 20
            }
          ]
        },
        {
          "id": "00004",
          "items": [
            {
              "quantity": 1,
              "price": 20
            }
          ]
        }
      ]
    }
  ]
}

预期输出JSON

{
  "orderId": "10001",
  "order_parts": [
    {
      "id": "00001",
      "items": [
        {
          "quantity": 1,
          "price": 20
        },
        {
          "quantity": 1,
          "price": 20
        }
      ]
    },
    {
      "id": "00004",
      "items": [
        {
          "quantity": 1,
          "price": 20
        }
      ]
    }
  ],
  "totalQuantity": [ 1, 1, 1 ]
}

实现逻辑说明

  • 直接从orders数组中提取订单的orderId和order_parts字段,映射到输出根节点,完整保留原有结构。
  • 通过嵌套遍历order_parts→各部件→items→各商品,用totalQuantity[]的语法将所有quantity值按遍历顺序追加到目标数组。
  • 所有操作在单次shift内完成,无需额外后续转换步骤。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 00:25:31