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

JOLT实现数组合并并为子元素添加父级键属性的问题咨询

JOLT 实现数组合并并新增父级属性脚本

你可以直接使用以下修改后的 JOLT 配置实现预期效果:

[
  {
    "operation": "shift",
    "spec": {
      "userData": {
        "entities": {
          "*": {
            "$2": "[&1].parent",
            "*": "[&1].&"
          }
        }
      },
      "programData": {
        "entities": {
          "*": {
            "$2": "[2].[&1].parent",
            "*": "[2].[&1].&"
          }
        }
      }
    }
  }
]

实现逻辑说明

  • 处理 userData.entities 下的数组元素时,将每个元素平放到外层数组的对应索引(&1 取当前数组元素的索引)位置,同时通过 $2 取向上两层的键名 userData 作为 parent 字段的值写入元素。
  • 处理 programData.entities 下的数组元素时,统一放到外层数组索引为 2 的子数组内,同时通过 $2 取向上两层的键名 programData 作为 parent 字段的值写入每个子元素。
    运行上述脚本后即可得到你提供的预期输出结构。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 08:15:05