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

Jolt复制数组到两层后删除单层级字段却全层级被删除问题排查

问题原因

你当前的规则触发问题的核心是Jolt的shift操作做数组多路径映射时,传递的是数组的引用而非深拷贝值:根路径accounts和ma-loan.accounts指向内存中同一个数组对象,你修改ma-loan.accounts下元素的字段时,根路径的数组元素也会同步变更,所以会出现两个层级的fullAccountNumber都被删除的情况。

解决方案

不需要额外的remove操作,直接在shift阶段分别构造两个数组即可:根路径的accounts全量拷贝所有字段,ma-loan下的accounts只映射需要保留的字段,避免后续修改引用带来的副作用。
正确的Jolt规则如下:

[
  {
    "operation": "shift",
    "spec": {
      "applicant": {
        "accounts": {
          "*": {
            // 全量映射到根路径accounts数组
            "@": "accounts[&1]",
            // 仅映射需要的字段到ma-loan下的accounts数组
            "maskedAccountNumber": "ma-loan.accounts[&1].maskedAccountNumber",
            "accountType": "ma-loan.accounts[&1].accountType"
          }
        }
      }
    }
  }
]

如果accounts下需要保留的字段较多,不想逐个枚举,也可以用以下规则,先做深拷贝再删除指定字段:

[
  {
    "operation": "shift",
    "spec": {
      "applicant": {
        "accounts": "accounts"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      // 深拷贝一份accounts到ma-loan节点下,两个数组完全独立
      "ma-loan": {
        "accounts": "@(1,accounts)"
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "ma-loan": {
        "accounts": {
          "*": {
            "fullAccountNumber": ""
          }
        }
      }
    }
  }
]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 03:06:04