I wanted to group the input array objects based on the fields profileName
, assetLevel1
, and assetLevel2
.
Input:
{
"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"
}
]
}
My current spec:
[
{
"operation": "shift",
"spec": {
"product": {
"*": "@profileName.@assetLevel1[]"
}
}
}
]
Desired output:
{
"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"
}
]
}
]
}
}
Can anyone help?
I have tried the above but unable to proceed as I am a newbie in this.
>Solution :
You can use this spec:
[
{
"operation": "shift",
"spec": {
"product": {
"*": "@profileName.@assetLevel1.@assetLevel2[]"
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"*": "MANY"
}
}
}
]