简体   繁体   English

在 Jolt Transformation 中循环时如何展平对象数组?

[英]How to flatten an array of objects while looping in Jolt Transformation?

I am trying to use Jolt to transform my incoming message into a list of certain custom objects.我正在尝试使用 Jolt 将收到的消息转换为特定自定义对象的列表。

However, in case of nested values in incoming array, I am not able to get the desired output.但是,对于传入数组中的嵌套值,我无法获得所需的输出。

Incoming message:传入消息:

[
  {
    "type": "Hourly",
    "employeeIdDetails": [
      {
        "id": "900",
        "idType": "HR_EMP"
      }
    ]
  },
  {
    "type": "Salaried",
    "employeeIdDetails": [
      {
        "id": "436",
        "idType": "SAL_EMP"
      },
      {
        "id": "111",
        "idType": "SAL_EMP"
      }
    ]
  },
  {
    "type": "Salaried",
    "employeeIdDetails": [
      {
        "id": "437",
        "idType": "SAL_EMP"
      }
    ]
  }
]

Jolt Spec震动规格

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "type": {
          "Salaried": {
            "@2": {
              "employeeIdDetails": {
                "*": {
                  "idType": {
                    "SAL_EMP": {
                      "@2": {
                        "id": "test[&4].ids",
                        "idType": "test[&4].types"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Current Output:当前输出:

{
  "test" : [ {
    "ids" : [ "436", "437" ],
    "types" : [ "SAL_EMP", "SAL_EMP" ]
  }, {
    "ids" : "111",
    "types" : "SAL_EMP"
  } ]
}

Expected Output预期产出

{
  "test" : [ {
    "ids" : "436",
    "types" : "SAL_EMP"
  } ,
{
    "ids" : "111",
    "types" : "SAL_EMP"
  } ,
 {
    "ids" : "437",
    "types" : "SAL_EMP"
  } ]
}

The order does not really matter to me other than having all the objects.除了拥有所有对象之外,顺序对我来说并不重要。

The problem, I think, I have found out so far is using "&".我认为,到目前为止我发现的问题是使用“&”。 But, not sure how I can combine values into 1 object without that.但是,不确定如何在没有它的情况下将值组合到 1 个对象中。

Maybe that way suits you?也许这种方式适合你?

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "type": {
          "Salaried": {
            "@(2,employeeIdDetails)": {
              "*": {
                "idType": {
                  "SAL_EMP": {
                    "@2": "test[]"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "test": {
        "*": {
          "id": "test[&1].ids",
          "idType": "test[&1].types"
        }
      }
    }
  }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM