JOLT 从数组中删除字段

JOLT remove the field from array

我必须在输出中将帐户复制到两级。从一个层面上,我需要删除 fullAccountNumber。但在我的震动规范中,它正在从两个级别中删除。我在 jolt 中删除规范时缺少什么吗?

我有以下输入

{
  "applicant": {
    "accounts": [
      {
        "fullAccountNumber": "00000000006276110961",
        "maskedAccountNumber": "XXXXXX0961",
        "accountType": "Checking"
      },
      {
        "fullAccountNumber": "00000000006276110961",
        "maskedAccountNumber": "XXXXXX0961",
        "accountType": "Saving"
      }
    ]
  }
}

期望的输出

{
  "accounts": [
    {
      "fullAccountNumber": "00000000006276110961",
      "maskedAccountNumber": "XXXXXX0961",
      "accountType": "Checking"
    },
    {
      "fullAccountNumber": "00000000006276110961",
      "maskedAccountNumber": "XXXXXX0961",
      "accountType": "Saving"
    }
  ],
  "ma-loan": {
    "accounts": [
      {
        "maskedAccountNumber": "XXXXXX0961",
        "accountType": "Checking"
      },
      {
        "maskedAccountNumber": "XXXXXX0961",
        "accountType": "Saving"
      }
    ]
  }
}

颠簸:

[
  {
    "operation": "shift",
    "spec": {
       "applicant": {
          "accounts": ["accounts", "ma-loan.accounts"]
       }
    }
  },
  {
    "operation": "remove",
    "spec": {
       "ma-loan": {
          "accounts": {
             "*": {
                  "fullAccountNumber": ""
               }
           }
       }
    }
  }
]

当前输出:(从两个级别中删除 fullAccountNumber)

{
  "accounts": [
    {
      "maskedAccountNumber": "XXXXXX0961",
      "accountType": "Checking"
    },
    {
      "maskedAccountNumber": "XXXXXX0961",
      "accountType": "Saving"
    }
  ],
  "ma-loan": {
    "accounts": [
      {
        "maskedAccountNumber": "XXXXXX0961",
        "accountType": "Checking"
      },
      {
        "maskedAccountNumber": "XXXXXX0961",
        "accountType": "Saving"
      }
    ]
  }
}

我找到了上述问题的解决方案。在我的例子中 remove 操作不起作用,我必须对第一个 shift[= 的结果使用 shift 操作24=] 操作规格

解决方案 1:

[
  {
    "operation": "shift",
    "spec": {
      "applicant": {
        "accounts": ["accounts", "ma-loan.accounts"]
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "ma-loan": {
        "*": "&1.&",
        "accounts": {
          "*": {
            "fullAccountNumber": {
              "*": {
                "@(2,maskedAccountNumber)": "&5.&4.[&3].maskedAccountNumber",
                "@(2,accountType)": "&5.&4.[&3].accountType"
              }
            }
          }
        }
      }
    }
  }
]

解决方案 2:

解决方案略有改进,使用单个 shift 操作。

[
  {
    "operation": "shift",
    "spec": {
      "applicant": {
        "accounts": {
          "*": {
            "fullAccountNumber": {
              "@": "accounts[].&"
            },
            "*": ["accounts[&1].&", "ma-loan.accounts[&1].&"]
          }
        }
      }
    }
  }
]