Created 02-28-2024 09:30 AM
Hello Team,
I have JSON like following
[
{
"INTEGRATION_ID": "1",
"ISSUE_STATUS_CAT": "Done",
"SPRINT_LIST": [
"24-w1-2",
"24-w1-3",
"24-w1-4"
]
},{
"INTEGRATION_ID": "2",
"ISSUE_STATUS_CAT": "Done",
"SPRINT_LIST": "24-w1-2"
}
]
My requirement is to check whether SPRINT_LIST is array or not. so I am using UpdateRecord processor with following formula
${field.value:startsWith(" [ ")}
I was getting the correct output earlier, where it returned 'True' when the value was a list and 'False' when it was null or not a list. However, after making some changes and then reverting back to the original settings, I started encountering issues. "Cannot convert value [true] of type class java.lang.String to Object Array for field error"
Created 02-28-2024 11:10 AM
Hi,
It depends on how you are setting the UpdateRecord processor. If you can provide screenshot it will help us figure out the issue. It seems you are trying to overwrite the field SPRINT_LIST and its complaining that you cannot convert Array to String because its already an array in the first record. May I suggest a different approach because the UpdateRecord you have to worry about setting the Record Writer\Reader and also you have to define the avro schema accordingly if you are planning to add new fields. Instead you can just use the Json Jolt Transformation processor with the following spec:
[
{
"operation": "shift",
"spec": {
"*": {
"SPRINT_LIST": {
"0": {
"#true": "[&3].is_sprint_array"
},
"@": "[&2].SPRINT_LIST"
},
"*": "[&1].&"
}
}
},
{
"operation": "default",
"spec": {
"*": {
"is_sprint_array": "false"
}
}
}
]
No need to set record reader\writer as long you know the input is always its valid json and has same schema. This will give you the following output:
[ {
"INTEGRATION_ID" : "1",
"ISSUE_STATUS_CAT" : "Done",
"SPRINT_LIST" : [ "24-w1-2", "24-w1-3", "24-w1-4" ],
"is_sprint_array" : "true"
}, {
"INTEGRATION_ID" : "2",
"ISSUE_STATUS_CAT" : "Done",
"SPRINT_LIST" : "24-w1-2",
"is_sprint_array" : "false"
} ]
If that helps please accept solution.
Thanks
Created 02-28-2024 11:10 AM
Hi,
It depends on how you are setting the UpdateRecord processor. If you can provide screenshot it will help us figure out the issue. It seems you are trying to overwrite the field SPRINT_LIST and its complaining that you cannot convert Array to String because its already an array in the first record. May I suggest a different approach because the UpdateRecord you have to worry about setting the Record Writer\Reader and also you have to define the avro schema accordingly if you are planning to add new fields. Instead you can just use the Json Jolt Transformation processor with the following spec:
[
{
"operation": "shift",
"spec": {
"*": {
"SPRINT_LIST": {
"0": {
"#true": "[&3].is_sprint_array"
},
"@": "[&2].SPRINT_LIST"
},
"*": "[&1].&"
}
}
},
{
"operation": "default",
"spec": {
"*": {
"is_sprint_array": "false"
}
}
}
]
No need to set record reader\writer as long you know the input is always its valid json and has same schema. This will give you the following output:
[ {
"INTEGRATION_ID" : "1",
"ISSUE_STATUS_CAT" : "Done",
"SPRINT_LIST" : [ "24-w1-2", "24-w1-3", "24-w1-4" ],
"is_sprint_array" : "true"
}, {
"INTEGRATION_ID" : "2",
"ISSUE_STATUS_CAT" : "Done",
"SPRINT_LIST" : "24-w1-2",
"is_sprint_array" : "false"
} ]
If that helps please accept solution.
Thanks
Created 02-29-2024 12:58 AM
Thank you @SAMSAL , I tried using JOLT, but when it didn't work, I resorted to using the UpdateRecords process. However, this is ultimately what I need.