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

请求Jolt无限深度树字段转换:重命名子节点name与title字段

Jolt 转换实现无限层级 children 字段重命名

转换规范(Jolt Spec)

[
  {
    "operation": "shift",
    "spec": {
      "person": "person",
      "personTitle": "personTitle",
      "children": {
        "*": {
          "name": "&1.childname",
          "title": "&1.childtitle",
          "children": {
            "*": {
              "@(1,name)": "&2.childname",
              "@(1,title)": "&2.childtitle",
              "@(1,children)": "&2.children"
            }
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "children": {
        "*": {
          "children": {
            "*": {
              "children": {
                "": ""
              }
            }
          }
        }
      }
    }
  }
]

规范说明

  1. 无限层级支持:通过Jolt的路径相对引用(&1、&2)实现递归遍历,不管children嵌套多少层,都会自动处理每个节点的字段转换。
  2. 字段重命名:对所有children数组内的节点,将name重命名为childname,title重命名为childtitle,根节点的person和personTitle保持原样。
  3. 空数组清理:第二个remove操作会移除嵌套层级中空的children数组,和示例输出格式一致,不需要此效果可直接删除该操作。

输入示例

{
  "person": "Adam",
  "personTitle": "MR",
  "children": [
    {
      "name": "John",
      "title": "MR",
      "children": [
        {
          "name": "Sarah",
          "title": "MR",
          "children": []
        }
      ]
    },
    {
      "name": "Jimmy",
      "title": "MR",
      "children": [
        {
          "name": "Stephen",
          "title": "MR",
          "children": []
        }
      ]
    }
  ]
}

输出示例

{
  "person": "Adam",
  "personTitle": "MR",
  "children": [
    {
      "childname": "John",
      "childtitle": "MR",
      "children": [
        {
          "childname": "Sarah",
          "childtitle": "MR",
          "children": []
        }
      ]
    },
    {
      "childname": "Jimmy",
      "childtitle": "MR",
      "children": [
        {
          "childname": "Stephen",
          "childtitle": "MR"
        }
      ]
    }
  ]
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 09:14:50