Jolt - 合并两个数组并重命名字段

Jolt - Merge two arrays and rename fields

我在将对象写入数组时遇到问题。基本上我想合并数组并重命名字段,同时单独保留对象。

我的输入 json 如下所示:

{
   "board":[
      {
         "role":"Head of board", 
         "id":"111",
         "name":"John Snow"
      }
   ],
   "leaders":[
      {
         "role":"Accounting leader",
         "id":"222",
         "name":"Amanda Johns"
      },
      {
         "role":"HR leader",
         "id":"333",
         "name":"Frank Smith"
      }
   ]
}

这是我的规格:(我知道括号中的值可能不正确)

[
   {
      "operation":"shift",
      "spec":{
         "board":{
            "*":{
               "id":"employees.bosses[#2].emp_num",
               "role":"employees.bosses[#2].position",
               "name":"employees.bosses[#2].name"
            }
         },
         "leaders":{
            "*":{
               "id":"employees.bosses[#2].emp_num",
               "role":"employees.bosses[#2].position",
               "name":"employees.bosses[#2].name"
            }
         }
      }
   }
]

这是我的输出:

{
    "employees": {
        "bosses": [ {
            "emp_num": ["111", "222"],
            "position": ["Head of board", "Accounting leader"],
            "name": ["John Snow", "Amanda Johns"]
        }, {
            "emp_num": "333",
            "position": "HR leader",
            "name": "Frank Smith"
        } ]
    }
}

虽然我希望输出看起来像这样:

{
    "employees": {
        "bosses": [ {
            "emp_num": "111",
            "position": "Head of board",
            "name": "John Snow"
        }, {
            "emp_num": "222",
            "position": "Accounting leader",
            "name": "Amanda Johns"
        }, {
            "emp_num": "333",
            "position": "HR leader",
            "name": "Frank Smith"
        } ]
    }
}

我很难理解该做什么以及 [#n] 是如何工作的,如果能帮助我修复我的规范并解释为什么这个 does/does 不起作用,我将不胜感激!

合并数组时需要区分数组的索引。为此,为第一个数组添加一个后缀字母或单词(这里我为 a.[&1] 选择 a),同时根据需要在第一个 shift 中重命名所有键操作,然后在连续的 shift 操作中应用新的扩展 employees.bosses 例如

[
  {
    "operation": "shift",
    "spec": {
      "board": {
        "*": {
          "id": "a.[&1].emp_num",
          "role": "a.[&1].position",
          "name": "a.[&1].name"
        }
      },
      "leaders": {
        "*": {
          "id": "&1.emp_num",
          "role": "&1.position",
          "name": "&1.name"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "employees.bosses"
    }
  }
]