Created 07-10-2024 06:09 PM
Hello,
Could you assist me in retrieving the single branchName value from priceRuleAttributes list based on id,
When i am doing without id match its working fine and giving me single branchName value for each index but with id match its combining all values at 1st index.
Input
{
"Data": {
"ID": "09878666",
"DATE": "2022-01-01",
"ARRAY_ONE": [
{
"NAME": "test_1",
"priceRuleAttributes": [
{
"type": "CFA",
"id": "PR_BRANCH_NAME",
"values": [
"MEMBERS"
]
},
{
"type": "CFA",
"id": "PR_PRICE_RULE_PROMO",
"valueBoolean": true
},
{
"type": "CFA",
"id": "PR_TARGET_SEGMENT",
"values": [
"1"
]
}
]
},
{
"NAME": "test_2",
"priceRuleAttributes": [
{
"type": "CFA",
"id": "PR_BRANCH_NAME",
"values": [
"NON MEMBERS"
]
},
{
"type": "CFA",
"id": "PR_PRICE_RULE_PROMO",
"valueBoolean": true
},
{
"type": "CFA",
"id": "PR_TARGET_SEGMENT",
"values": [
"1"
]
}
]
}
]
}
}
Spec
[
{
"operation": "shift",
"spec": {
"Data": {
"ARRAY_ONE": {
"*": {
"@(2,ID)": "[#2].ID",
"@(2,DATE)": "[#2].DATE",
"NAME": "[#2].NAME",
"priceRuleAttributes": {
"*": {
"id": {
"PR_BRANCH_NAME": {
"@(2,values)": "[#4].branchName"
}
}
}
}
}
}
}
}
}
]
Expected Output
[ {
"ID" : "09878666",
"DATE" : "2022-01-01",
"NAME" : "test_1",
"branchName" : [ "MEMBERS" ]
}, {
"ID" : "09878666",
"DATE" : "2022-01-01",
"NAME" : "test_2",
"branchName" : [ "NON MEMBERS" ]
} ]
Actual output
Created 07-11-2024 02:32 AM
Hi,
I think you are confusing the grouping function represented by # with the reference function using &. what you need to do is actually reference the ARRAY_ONE index to group the fields properly.
[
{
"operation": "shift",
"spec": {
"Data": {
"ARRAY_ONE": {
"*": {
//&1 refernce the index above so you will have two elements
"@(2,ID)": "[&1].ID",
"@(2,DATE)": "[&1].DATE",
"NAME": "[&1].NAME",
"priceRuleAttributes": {
"*": {
"id": {
"PR_BRANCH_NAME": {
//&5 refernce ARRAY_ONE index at level 5 starting from this level (0)
"@(2,values)": "[&5].branchName"
}
}
}
}
}
}
}
}
}
]
If you found this helpful please accept solution.
Thanks
Created 07-11-2024 02:32 AM
Hi,
I think you are confusing the grouping function represented by # with the reference function using &. what you need to do is actually reference the ARRAY_ONE index to group the fields properly.
[
{
"operation": "shift",
"spec": {
"Data": {
"ARRAY_ONE": {
"*": {
//&1 refernce the index above so you will have two elements
"@(2,ID)": "[&1].ID",
"@(2,DATE)": "[&1].DATE",
"NAME": "[&1].NAME",
"priceRuleAttributes": {
"*": {
"id": {
"PR_BRANCH_NAME": {
//&5 refernce ARRAY_ONE index at level 5 starting from this level (0)
"@(2,values)": "[&5].branchName"
}
}
}
}
}
}
}
}
}
]
If you found this helpful please accept solution.
Thanks
Created on 07-11-2024 07:41 AM - edited 07-11-2024 07:45 AM
Thanks its working fine.
Created on 07-11-2024 08:22 AM - edited 07-11-2024 10:42 AM
can i get single value instead of array ?
"branchName" : ["MEMBERS"] --> "branchName" : "MEMBERS"
[ {
"ID" : "09878666",
"DATE" : "2022-01-01",
"NAME" : "test_1",
"branchName" : "MEMBERS",
}, {
"ID" : "09878666",
"DATE" : "2022-01-01",
"NAME" : "test_2",
"branchName" : "NON MEMBERS"
} ]