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

编写Jolt规格移除externalIds数组中重复的externalId元素

Jolt 规格实现移除重复的externalId元素

输入JSON

{
  "id": "id_1",
  "targetId": "targetId42",
  "externalId": "1extid",
  "attributes": {
    "uniqueInfo": {
      "externalIds": [
        "3extid",
        "2extid",
        "4extid",
        "1extid",
        "5extid"
      ]
    }
  }
}

期望输出JSON

{
  "id": "id_1",
  "targetId": "targetId42",
  "externalId": "1extid",
  "attributes": {
    "uniqueInfo": {
      "externalIds": [
        "3extid",
        "2extid",
        "4extid",
        "5extid"
      ]
    }
  }
}

Jolt 规格

[
  {
    "operation": "shift",
    "spec": {
      "id": "id",
      "targetId": "targetId",
      "externalId": "externalId",
      "attributes": {
        "uniqueInfo": {
          "externalIds": {
            "*": {
              "@": "[#3].attributes.uniqueInfo.externalIds[#2]",
              "$": "[#3].temp[#2]",
              "@(4,externalId)": "[#3].matchVal"
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "attributes": {
          "uniqueInfo": {
            "externalIds": "=filter(@(3,temp),@(3,matchVal))"
          }
        },
        "temp": "",
        "matchVal": ""
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": ""
    }
  }
]

规格说明

  1. Shift 操作:映射原数据的所有字段,同时将externalIds数组的每个元素、对应索引值,以及顶层externalId存入临时字段,为过滤做准备。
  2. Modify-overwrite-beta 操作:通过filter函数筛选出不等于顶层externalId的数组元素,随后清空临时字段。
  3. 最终 Shift 操作:扁平化处理后的结构,得到目标输出。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 19:50:21