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

时间:2020-11-12 21:14:42

标签: jolt

我的输入定义为

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

我希望得到的输出为

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

任何帮助将不胜感激。

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

我尝试过的不完整转换:

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

编辑:立即尝试

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

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

edit2:

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

1 个答案:

答案 0 :(得分:0)

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


function deleterow(event, id) {

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

}