Skip to main content
Syed0000
Silver ⭐️⭐️⭐️
Jul 11, 2024 1:09 AM UTC
Solved

Extracting List Elements using JOLT

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

Syed0000_0-1720659770483.png

 

 

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
Jul 11, 2024 9:32 AM UTC

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

3 replies

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
Jul 11, 2024 9:32 AM UTC

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

Translate
Syed0000
Syed0000Author
Silver ⭐️⭐️⭐️
Jul 11, 2024 2:41 PM UTC

Thanks its working fine.

Translate
Syed0000
Syed0000Author
Silver ⭐️⭐️⭐️
Jul 11, 2024 3:22 PM UTC

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"
} ]

 

 

Translate