Support Questions

Find answers, ask questions, and share your expertise

Extracting List(Array) element using JOLT

avatar
Expert Contributor

Hello,

Can you assist me in retrieving the values stored in the "customfield_10161field from JSON input? My expectation is to consistently receive the values and name it "DEFECT_ROOT_CAUSE" , whether they are stored as a list or as a single value."

How to write JOLT which will handle the both the case. let say If I will get list then extract last element of it, if not list then record as it is.?

Extracting List: (works fine when input is list)

saquibsk_0-1713731749160.png

when input is not list: 

then DEFECT_ROOT_CAUSE column is missing My expectation to get the records in DEFECT_ROOT_CAUSE columns whether its list or not.

saquibsk_1-1713731973678.png

 

 

 

 

 

Shakib M.
1 ACCEPTED SOLUTION

avatar
Super Guru

Based on the provided new input and the expected output as I was able to understand where you always want to consider the last element of both DEFECT_ROOT_CAUSE & SPRINT_LIST which both may or may not be an array of values, I would take a different approach to the jolt spec which is much simpler as follows:

 

 

[
  // First spec is convert everything into list regardless
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "SPRINT_LIST": "MANY",
        "DEFECT_ROOT_CAUSE": "MANY"
      }
    }
  }
  ,
  // From the generated list above return last element
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "SPRINT_LIST": "=lastElement",
        "DEFECT_ROOT_CAUSE": "=lastElement"
      }
    }
  }

]

 

 

 

View solution in original post

16 REPLIES 16

avatar
Super Guru

The reason its not working because there is mismatch in the list name 3rd spec where its using "DEFECT_ROOT_CAUSE_LIST" and the 4th spec where its using "DIRECT_ROOT_CAUSE_LIST" . If you fix this it should work. 

If you find this is helpful please accept solution.

Thanks

avatar
Expert Contributor

Thank you very much, @SAMSAL. I really appreciate your time and effort.

My input format has changed. I will adjust the JOLT accordingly if it does not work or encounter any issues, I will ask one final question. Otherwise, I will mark your last reply as the solution.

Shakib M.

avatar
Expert Contributor

Just to give a heads up, my input will be something like the example below. I have around 60 columns, and out of those, only 4 columns are in the list.

Example: from below example i would like to handle the "DEFECT_ROOT_CAUSE" and "SPRINT_LIST" 

Output would be same as your solution:

DEFECT_ROOT_CAUSE:"Frontend"

SPRINT_LIST:"24-w2-3"

 

 

==================================
-- input 1
==================================

[ {
  "INTEGRATION_ID" : "1111",
  "ISSUE_KEY" : "PP2-7426",
  "SUMMARY" : "Confirmation Web",
  "SPRINT_LIST" :"24-w2-1",
  "DEFECT_TYPE" : "poor user interface design, confusing navigation",
  "TEAM" : "Web Engineering",
  "PLATFORM" : "Customer Web",
  "DEFECT_ROOT_CAUSE" : [ "Backend", "Frontend" ]
  }
]  


==================================
-- input 2
================================== 


[ {
  "INTEGRATION_ID" : "2222",
  "ISSUE_KEY" : "PP2-7427",
  "SUMMARY" : "Confirmation Web",
  "SPRINT_LIST" : [ "24-w2-1", "24-w2-2", "24-w2-3" ],
  "DEFECT_TYPE" : "poor user interface design, confusing navigation",
  "TEAM" : "Web Engineering",
  "PLATFORM" : "Customer Web",
  "DEFECT_ROOT_CAUSE" : "Backend"
  }
]

 

Shakib M.

avatar
Super Guru

Based on the provided new input and the expected output as I was able to understand where you always want to consider the last element of both DEFECT_ROOT_CAUSE & SPRINT_LIST which both may or may not be an array of values, I would take a different approach to the jolt spec which is much simpler as follows:

 

 

[
  // First spec is convert everything into list regardless
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "SPRINT_LIST": "MANY",
        "DEFECT_ROOT_CAUSE": "MANY"
      }
    }
  }
  ,
  // From the generated list above return last element
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "SPRINT_LIST": "=lastElement",
        "DEFECT_ROOT_CAUSE": "=lastElement"
      }
    }
  }

]

 

 

 

avatar
Expert Contributor

Thank you, @SAMSAL. This logic is much simpler. My JOLT logic was a bit complex. This is going to save me a lot of time.

Is there are any tutorial where we can learn the JOLT ?

Shakib M.

avatar
Super Guru

There is not really a comprehensive Jolt tutorial that I could find out there. Two important references I frequently use to learn is :

1- The Jolt code in github where you can see how things work under the hood and what are the available functions:

https://github.com/bazaarvoice/jolt

2- A site that talks about the fundamental of jolt:

https://docs.digibee.com/documentation/components/tools/transformer-jolt/transformer-getting-to-know...

The rest is practice, practice and more practice. Its the only way you can get some depth in the understanding of jolt and its capabilities.  You can do that by trying to help and learn from others posts in this community forum or other forums like the below where you can find tons of jolt problems\solutions:

https://stackoverflow.com/questions/tagged/jolt

Hope that helps and thanks for accepting the solution.

 

 

avatar
New Contributor

hi SAMSAL, i send you message. Can you check it please ?