json 基于对象内部字段的Jolt转换器分组

soat7uwm  于 2023-02-26  发布在  其他
关注(0)|答案(1)|浏览(130)

我想根据字段profileNameassetLevel1assetLevel2对输入数组对象进行分组。

    • 输入:**
{
  "product": [
    {
      "id": "id1",
      "entity": "entity1",
      "productID": "productID1",
      "productName": "productName1",
      "unitPrice": "unitPrice1",
      "assetLevel1": "Equities",
      "assetLevel2": "US Large Cap Equity",
      "profileName": "Beginner Level"
    },
    {
      "id": "id3",
      "entity": "entity3",
      "productID": "productID3",
      "productName": "productName3",
      "unitPrice": "unitPrice3",
      "assetLevel1": "Fixed Income",
      "assetLevel2": "Global Aggregate Funds",
      "profileName": "Novice Level"
    },
    {
      "id": "id2",
      "entity": "entity2",
      "productID": "productID2",
      "productName": "productName2",
      "unitPrice": "unitPrice2",
      "assetLevel1": "Equities",
      "assetLevel2": "US Large Cap Equity",
      "profileName": "Beginner Level"
    }
  ]
}
    • 我的当前规格:**
[
  {
    "operation": "shift",
    "spec": {
      "product": {
        "*": "@profileName.@assetLevel1[]"
      }
    }
  }
]
    • 预期产出:**
{
  "Beginner Level": {
    "Equities": [
      {
        "US Large Cap Equity": [
          {
            "assetLevel1": "Equities",
            "assetLevel2": "US Large Cap Equity",
            "entity": "entity1",
            "id": "id1",
            "productID": "productID1",
            "productName": "productName1",
            "profileName": "Beginner Level",
            "unitPrice": "unitPrice1"
          },
          {
            "assetLevel1": "Equities",
            "assetLevel2": "US Large Cap Equity",
            "entity": "entity2",
            "id": "id2",
            "productID": "productID2",
            "productName": "productName2",
            "profileName": "Beginner Level",
            "unitPrice": "unitPrice2"
          }
        ]
      }
    ]
  },
  "Novice Level": {
    "Fixed Income": [
      {
        "Global Aggregate Funds": [
          {
            "assetLevel1": "Fixed Income",
            "assetLevel2": "Global Aggregate Funds",
            "entity": "entity3",
            "id": "id3",
            "productID": "productID3",
            "productName": "productName3",
            "profileName": "Novice Level",
            "unitPrice": "unitPrice3"
          }
        ]
      }
    ]
  }
}

有人能帮忙吗?
我已经尝试了上述,但无法进行,因为我是一个新手在这方面。

wgeznvg7

wgeznvg71#

可以使用此等级库:

[
  {
    "operation": "shift",
    "spec": {
      "product": {
        "*": "@profileName.@assetLevel1.@assetLevel2[]"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": "MANY"
      }
    }
  }
]

相关问题