Created on 04-21-2024 01:24 PM - edited 04-21-2024 01:45 PM
Hello,
Can you assist me in retrieving the values stored in the "customfield_10161" field 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)
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.
Created on 05-06-2024 02:21 PM - edited 05-06-2024 02:21 PM
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"
}
}
}
]
Created 05-06-2024 07:05 AM
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
Created 05-06-2024 01:42 PM
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.
Created 05-06-2024 01:54 PM
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"
}
]
Created on 05-06-2024 02:21 PM - edited 05-06-2024 02:21 PM
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"
}
}
}
]
Created on 05-06-2024 11:42 PM - edited 05-06-2024 11:43 PM
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 ?
Created 05-07-2024 10:29 PM
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:
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.
Created 06-05-2024 12:31 AM
hi SAMSAL, i send you message. Can you check it please ?