将一个数组移到另一个数组中定义的json对象中-JOLT Transformation

问题描述

我的输入定义为

{
    "lineId": "1","Collection": {
        "services": [
            {
                "Code": "TB","Type": [
                    "Data"
                ]
            },{
                "Code": "MAGTB","Type": [
                    "Data"
                ]
            }
        ]
    },"promotions": [
        {
            "Id": "1"
        },{
            "Id": "2"
        }
    ]
}

我希望得到的输出

{
    "lineId": "1","Type": [
                    "Data"
                ],"promotions": [
                    {
                        "Id": "1"
                    },{
                        "Id": "2"
                    }
                ]
            },{
                "Code": "TB2",{
                        "Id": "2"
                    }
                ]
            }
        ]
    }
}

任何帮助将不胜感激。

我是JOLT的新手。而且我无法从第一个数组中导航到第二个数组。

我尝试过的不完整转换:

[
  {
    "operation": "shift","spec": {
      "Collection": {
        "services": {
     
          "*": "Collection.services[].&","@(3,lineId)": "lineId",promotions)":{
            "*":
          }
        }
      }
    }
  }
]

编辑:立即尝试

[
  {
    "operation": "shift","spec": {
      "Collection": {
        "services": {
          "*": "Collection.services[]",//  "*": "&",promotions)": {
            "*": {
              "Id": "Id"
            }
          }
        }
      }
    }
  }
]

我只需要找出一种将ID列表移到services数组中的对象内部的方法

edit2:

[
  {
    "operation": "shift","spec": {
      "Collection": {
        "services": {
          "*": {
            "*": "Collection.services[&1].&",lineId)": "Collection.services[&1].lineId",promotions)": "Collection.services[&1].promotions"
          }
        }
      }
    }
  }
]

解决方法

我认为这是您正在寻找的规格?


function deleterow(event,id) {

    event.preventDefault();
    var elem = document.getElementById(id);
    elem.parentElement.removeChild(elem);

}