Jolt 将具有数组的对象转换为单个数组

Jolt transform an object with an array to a single array

大家好,我的 json 输入是这样的:

{
  "chequesCollateral": [
    {
      "accountNum": "0026.0002.62.0300162968",
      "agreement": "0026.5501.90.0490520505",
      "checkno": "229425941           ",
      "amount": 20000,
      "issueBank": "0026",
      "branch": "0154",
      "currency": "EUR",
      "expDate": "2019-09-20"
    },
    {
      "accountNum": "0026.0002.62.0300162968",
      "agreement": "0026.5501.90.0490520505",
      "checkno": "322108888           ",
      "amount": 2500,
      "issueBank": "0011",
      "branch": "0335",
      "currency": "EUR",
      "expDate": "2019-10-26"
    },
    {
      "accountNum": "0026.0002.62.0300162968",
      "agreement": "0026.5501.90.0490520505",
      "checkno": "321979826           ",
      "amount": 3964.77,
      "issueBank": "0011",
      "branch": "0104",
      "currency": "EUR",
      "expDate": "2019-10-31"
    }
  ]
}

我使用这个转换来生成这个:

[
  {
    "operation": "shift",
    "spec": {
      "chequesCollateral": {
        "*": {
          "issueBank": "distinctBinData.&0"
        }
      }
    }
  }
]

这是产生的:

{
  "distinctBinData" : {
    "issueBank" : [ "0026", "0011", "0011" ]
  }
}

我想制作这个:

{
  "distinctBinData" : [ "0026", "0011", "0011" ]
}

我该怎么办?

您不必在目标键中指定 &0 部分。 &0 指的是当前级别 JSON 密钥,在您的情况下是 issueBank 。因此,当您将目标键指定为 distinctBinData.&0 时,它会解析为 distinctBinData.issueBank。所以只需使用 distinctBinData 作为目标键,如下所示。

[
{
    "operation": "shift",
    "spec": {
        "chequesCollateral": {
            "*": {
                "issueBank": "distinctBinData"
            }
        }
    }
}
]