Support Questions

Find answers, ask questions, and share your expertise
Announcements
We’ve updated our product names and community labels - click here for full details

Extracting List Elements using JOLT

avatar
Contributor

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

 

 

1 ACCEPTED SOLUTION

avatar
Super Guru

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

View solution in original post

3 REPLIES 3

avatar
Super Guru

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

avatar
Contributor

Thanks its working fine.

avatar
Contributor

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